|
133 | 133 | "Pikachu"))) |
134 | 134 |
|
135 | 135 | (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.)")))) |
140 | 140 |
|
141 | 141 | (deftest transformations |
142 | 142 | (with-open [conn (r/connect :db test-db)] |
143 | 143 | (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])) |
151 | 162 |
|
152 | 163 | (testing "skip" |
153 | 164 | (are [term result] (= (r/run term conn) result) |
|
0 commit comments