|
6 | 6 | (and (sequential? x) |
7 | 7 | (clojure.core/empty? x))) |
8 | 8 |
|
9 | | -(facts "product" |
| 9 | +(facts "ex 1 product" |
10 | 10 | (product []) => 1 |
11 | 11 | (product [1 2 3]) => 6 |
12 | 12 | (product [1 2 3 4]) => 24 |
13 | 13 | (product [0 1 2]) => 0 |
14 | 14 | (product #{2 3 4}) => 24) |
15 | 15 |
|
16 | | -(facts "singleton?" |
| 16 | +(facts "ex 3 singleton?" |
17 | 17 | (singleton? [1]) => true |
18 | 18 | (singleton? #{2}) => true |
19 | 19 | (singleton? []) => false |
20 | 20 | (singleton? [1 2 3]) => false) |
21 | 21 |
|
22 | | -(facts "my-last" |
| 22 | +(facts "ex 4 my-last" |
23 | 23 | (my-last []) => nil |
24 | 24 | (my-last [1 2 3]) => 3 |
25 | 25 | (my-last [2 5]) => 5) |
26 | 26 |
|
27 | | -(facts "max-element" |
| 27 | +(facts "ex 5 max-element" |
28 | 28 | (max-element [2 4 1 4]) => 4 |
29 | 29 | (max-element [2]) => 2 |
30 | 30 | (max-element []) => nil) |
31 | 31 |
|
32 | | -(facts "seq-max" |
| 32 | +(facts "ex 6 seq-max" |
33 | 33 | (seq-max [1] [1 2]) => [1 2] |
34 | 34 | (seq-max [1 2] [3 4]) => [3 4]) |
35 | 35 |
|
36 | | -(facts "longest-sequence" |
| 36 | +(facts "ex 7 longest-sequence" |
37 | 37 | (longest-sequence [[1 2] [] [1 2 3]]) => [1 2 3] |
38 | 38 | (longest-sequence [[1 2]]) => [1 2] |
39 | 39 | (longest-sequence []) => nil) |
40 | 40 |
|
41 | | -(facts "my-filter" |
| 41 | +(facts "ex 8 my-filter" |
42 | 42 | (my-filter odd? [1 2 3 4]) => '(1 3) |
43 | 43 | (my-filter (fn [x] (> x 9000)) [12 49 90 9001]) => '(9001) |
44 | 44 | (my-filter even? [1 3 5 7]) => empty?) |
45 | 45 |
|
46 | | -(facts "sequence-contains?" |
| 46 | +(facts "ex 9 sequence-contains?" |
47 | 47 | (sequence-contains? 3 [1 2 3]) => true |
48 | 48 | (sequence-contains? 3 [4 7 9]) => false |
49 | 49 | (sequence-contains? :pony []) => false) |
50 | 50 |
|
51 | | -(facts "my-take-while" |
| 51 | +(facts "ex 10 my-take-while" |
52 | 52 | (my-take-while odd? [1 2 3 4]) => '(1) |
53 | 53 | (my-take-while odd? [1 3 4 5]) => '(1 3) |
54 | 54 | (my-take-while even? [1 3 4 5]) => empty? |
55 | 55 | (my-take-while odd? []) => empty?) |
56 | 56 |
|
57 | | -(facts "my-drop-while" |
| 57 | +(facts "ex 11 my-drop-while" |
58 | 58 | (my-drop-while odd? [1 2 3 4]) => '(2 3 4) |
59 | 59 | (my-drop-while odd? [1 3 4 5]) => '(4 5) |
60 | 60 | (my-drop-while even? [1 3 4 5]) => '(1 3 4 5) |
61 | 61 | (my-drop-while odd? []) => empty?) |
62 | 62 |
|
63 | | -(facts "seq=" |
| 63 | +(facts "ex 12 seq=" |
64 | 64 | (seq= [1 2 4] '(1 2 4)) => true |
65 | 65 | (seq= [1 2 3] [1 2 3 4]) => false |
66 | 66 | (seq= [1 3 5] []) => false) |
67 | 67 |
|
68 | | -(facts "my-map" |
| 68 | +(facts "ex 13 my-map" |
69 | 69 | (my-map + [1 2 3] [4 4 4]) => '(5 6 7) |
70 | 70 | (my-map + [1 2 3 4] [0 0 0]) => '(1 2 3) |
71 | 71 | (my-map + [1 2 3] []) => empty?) |
72 | 72 |
|
73 | | -(facts "power" |
| 73 | +(facts "ex 14 power" |
74 | 74 | (power 2 2) => 4 |
75 | 75 | (power 5 3) => 125 |
76 | 76 | (power 7 0) => 1 |
77 | 77 | (power 0 10) => 0) |
78 | 78 |
|
79 | | -(facts "fib" |
| 79 | +(facts "ex 15 fib" |
80 | 80 | (fib 0) => 0 |
81 | 81 | (fib 1) => 1 |
82 | 82 | (fib 2) => 1 |
|
86 | 86 | (fib 6) => 8 |
87 | 87 | (fib 10) => 55) |
88 | 88 |
|
89 | | -(facts "my-repeat" |
| 89 | +(facts "ex 16 my-repeat" |
90 | 90 | (my-repeat 2 :a) => '(:a :a) |
91 | 91 | (my-repeat 3 "lol") => '("lol" "lol" "lol") |
92 | 92 | (my-repeat -1 :a) => empty?) |
93 | 93 |
|
94 | | -(facts "my-range" |
| 94 | +(facts "ex 17 my-range" |
95 | 95 | (my-range 0) => empty? |
96 | 96 | (my-range 1) => '(0) |
97 | 97 | (my-range 2) => '(1 0) |
98 | 98 | (my-range 3) => '(2 1 0)) |
99 | 99 |
|
100 | | -(facts "tails" |
| 100 | +(facts "ex 18 tails" |
101 | 101 | (tails [1 2 3 4]) => (just [[1 2 3 4] [2 3 4] [3 4] [4] []] :in-any-order) |
102 | 102 | (tails []) => (just [[]]) |
103 | 103 | (tails [1]) => (just [[1] []] :in-any-order)) |
104 | 104 |
|
105 | | -(facts "inits" |
| 105 | +(facts "ex 18 inits" |
106 | 106 | (inits [1 2 3 4]) => (just [[] [1] [1 2] [1 2 3] [1 2 3 4]] :in-any-order) |
107 | 107 | (inits []) => (just [[]]) |
108 | 108 | (inits [1]) => (just [[] [1]] :in-any-order)) |
109 | 109 |
|
110 | | -(facts "rotations" |
| 110 | +(facts "ex 19 rotations" |
111 | 111 | (rotations []) => '(()) |
112 | 112 | (rotations [1 2 3]) => (just [[1 2 3] [2 3 1] [3 1 2]] :in-any-order) |
113 | 113 | (rotations [:a :b]) => (just [[:a :b] [:b :a]] :in-any-order) |
|
116 | 116 | :in-any-order) |
117 | 117 | (count (rotations [6 5 8 9 2])) => 5) |
118 | 118 |
|
119 | | -(facts "my-frequencies" |
| 119 | +(facts "ex 20 my-frequencies" |
120 | 120 | (my-frequencies []) => {} |
121 | 121 | (my-frequencies [1 1 2 2 :D :D :D]) => {1 2, 2 2, :D 3} |
122 | 122 | (my-frequencies [:a "moi" :a "moi" "moi" :a 1]) |
123 | 123 | => {:a 3, "moi" 3, 1 1}) |
124 | 124 |
|
125 | | -(facts "un-frequencies" |
| 125 | +(facts "ex 21 un-frequencies" |
126 | 126 | (un-frequencies {:a 3 :b 2 "^_^" 1}) |
127 | 127 | => (just [:a :a :a "^_^" :b :b] :in-any-order) |
128 | 128 | (un-frequencies (my-frequencies [:a :b :c :a])) |
129 | 129 | => (just [:a :a :b :c] :in-any-order) |
130 | 130 | (my-frequencies (un-frequencies {:a 100 :b 10})) |
131 | 131 | => {:a 100 :b 10}) |
132 | 132 |
|
133 | | -(facts "my-take" |
| 133 | +(facts "ex 22 my-take" |
134 | 134 | (my-take 2 [1 2 3 4]) => '(1 2) |
135 | 135 | (my-take 4 [:a :b]) => '(:a :b)) |
136 | 136 |
|
137 | | -(facts "my-drop" |
| 137 | +(facts "ex 23 my-drop" |
138 | 138 | (my-drop 2 [1 2 3 4]) => '(3 4) |
139 | 139 | (my-drop 4 [:a :b]) => empty?) |
140 | 140 |
|
141 | | -(facts "halve" |
| 141 | +(facts "ex 24 halve" |
142 | 142 | (halve [1 2 3 4]) => ['(1 2) '(3 4)] |
143 | 143 | (halve [1 2 3 4 5]) => ['(1 2) '(3 4 5)] |
144 | 144 | (halve [1]) => (just empty? '(1))) |
145 | 145 |
|
146 | | -(facts "seq-merge" |
| 146 | +(facts "ex 25 seq-merge" |
147 | 147 | (seq-merge [4] [1 2 6 7]) => '(1 2 4 6 7) |
148 | 148 | (seq-merge [1 5 7 9] [2 2 8 10]) => '(1 2 2 5 7 8 9 10)) |
149 | 149 |
|
150 | | -(facts "merge-sort" |
| 150 | +(facts "ex 26 merge-sort" |
151 | 151 | (merge-sort []) => empty? |
152 | 152 | (merge-sort [1 2 3]) => '(1 2 3) |
153 | 153 | (merge-sort [5 3 4 17 2 100 1]) => '(1 2 3 4 5 17 100)) |
154 | 154 |
|
155 | | -(facts "split-into-monotonics" |
| 155 | +(facts "ex 27 split-into-monotonics" |
156 | 156 | (split-into-monotonics [0 1 2 1 0]) => '((0 1 2) (1 0)) |
157 | 157 | (split-into-monotonics [0 5 4 7 1 3]) => '((0 5) (4 7) (1 3))) |
158 | 158 |
|
159 | | -(facts "permutations" |
| 159 | +(facts "ex 28 permutations" |
160 | 160 | (permutations []) => (just empty?) |
161 | 161 | (count (permutations (range 5))) => 120 |
162 | 162 | (permutations [1 5 3]) |
163 | 163 | => (just [1 5 3] [5 1 3] [5 3 1] [1 3 5] [3 1 5] [3 5 1] |
164 | 164 | :in-any-order)) |
165 | 165 |
|
166 | | -(facts "powerset" |
| 166 | +(facts "ex 29 powerset" |
167 | 167 | (powerset []) => (some-checker (just empty?) (just #{#{}})) |
168 | 168 | (powerset [1 2 4]) => (some-checker |
169 | 169 | (just empty? |
|
0 commit comments