Skip to content

Commit 22ddfe6

Browse files
committed
Add tests for desc, with-fields, concat-map. Relates to #117.
1 parent a75de30 commit 22ddfe6

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

test/rethinkdb/core_test.clj

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -133,21 +133,32 @@
133133
"Pikachu")))
134134

135135
(testing "default values"
136-
(is (= "not found" (r/run (-> (r/get-field {:a 1} :b) (r/default "not found")) conn)))
137-
(is (= "not found" (r/run (-> (r/max [nil]) (r/default "not found")) conn)))
138-
(is (= "Cannot take the average of an empty stream. (If you passed `avg` a field name, it may be that no elements of the stream had that field.)"
139-
(r/run (-> (r/avg [nil]) (r/default (r/fn [row] row))) conn))))))
136+
(are [term result] (= result (r/run term conn))
137+
(-> (r/get-field {:a 1} :b) (r/default "not found")) "not found"
138+
(-> (r/max [nil]) (r/default "not found")) "not found"
139+
(-> (r/avg [nil]) (r/default (r/fn [row] row))) "Cannot take the average of an empty stream. (If you passed `avg` a field name, it may be that no elements of the stream had that field.)"))))
140140

141141
(deftest transformations
142142
(with-open [conn (r/connect :db test-db)]
143143
(testing "order-by + map"
144-
(is (= [25 81] ((r/run (-> (r/table test-table) (r/insert pokemons)) conn)
145-
(r/run (-> (r/table test-table) r/sync) conn)
146-
(r/run (-> (r/table test-table)
147-
(r/order-by {:index (r/asc :national_no)})
148-
(r/map (r/fn [row]
149-
(r/get-field row :national_no))))
150-
conn)))))
144+
(r/run (-> (r/table test-table) (r/insert pokemons)) conn)
145+
(r/run (-> (r/table test-table) r/sync) conn)
146+
(are [order result] (= result (r/run (-> (r/table test-table)
147+
(r/order-by {:index (order :national_no)})
148+
(r/map (r/fn [row]
149+
(r/get-field row :national_no))))
150+
conn))
151+
r/asc [25 81]
152+
r/desc [81 25]))
153+
154+
(testing "with-fields"
155+
(are [term result] (= (r/run term conn) result)
156+
(r/with-fields pokemons ["name"]) [{:name "Pikachu"} {:name "Magnemite"}]
157+
(r/with-fields pokemons ["color"]) []))
158+
159+
(testing "concat-map"
160+
(are [term result] (= (r/run term conn) result)
161+
(r/concat-map [1 6 1 8] (r/fn [e] [e (r/mul 2 e)])) [1 2 6 12 1 2 8 16]))
151162

152163
(testing "skip"
153164
(are [term result] (= (r/run term conn) result)

0 commit comments

Comments
 (0)