File tree 2 files changed +45
-0
lines changed
src/data_structures/queue
test/data_structures/queue
2 files changed +45
-0
lines changed Original file line number Diff line number Diff line change
1
+ (ns data-structures.queue.vector )
2
+
3
+ (defn ->Queue
4
+ []
5
+ [])
6
+
7
+ (defn enqueue
8
+ [queue value]
9
+ (conj queue value))
10
+
11
+ (defn dequeue
12
+ [queue]
13
+ (if (empty? queue)
14
+ queue
15
+ (subvec queue 1 )))
16
+
17
+ (defn peek-queue
18
+ [queue]
19
+ (first queue))
20
+
21
+ (defn empty-queue?
22
+ [queue]
23
+ (empty? queue))
Original file line number Diff line number Diff line change
1
+ (ns data-structures.queue.vector-test
2
+ (:require
3
+ [clojure.test :refer [deftest testing is]]
4
+ [data-structures.queue.vector :as q]))
5
+
6
+ (deftest ->Queue-test
7
+ (is (vector? (q/->Queue ))))
8
+
9
+ (deftest enqueue-test
10
+ (is (= [10 20 30 ] (-> (q/->Queue ) (q/enqueue 10 ) (q/enqueue 20 ) (q/enqueue 30 )))))
11
+
12
+ (deftest dequeue-test
13
+ (is (= [] (-> (q/->Queue ) (q/dequeue ))))
14
+ (is (= [20 30 ] (-> (q/->Queue ) (q/enqueue 10 ) (q/enqueue 20 ) (q/enqueue 30 ) (q/dequeue )))))
15
+
16
+ (deftest peek-queue-test
17
+ (is (nil? (-> (q/->Queue ) (q/peek-queue ))) " returns nil for empty queue" )
18
+ (is (= 10 (-> (q/->Queue ) (q/enqueue 10 ) (q/enqueue 20 ) (q/enqueue 30 ) (q/peek-queue )))))
19
+
20
+ (deftest empty-queue?-test
21
+ (is (q/empty-queue? (q/->Queue )))
22
+ (is (false ? (-> (q/->Queue ) (q/enqueue 10 ) (q/enqueue 20 ) q/empty-queue?))))
You can’t perform that action at this time.
0 commit comments