Skip to content

Instantly share code, notes, and snippets.

@deque-blog
Last active March 7, 2017 21:39
Show Gist options
  • Save deque-blog/015b4ce251237afe3d3fd840b98c8fe1 to your computer and use it in GitHub Desktop.
Save deque-blog/015b4ce251237afe3d3fd840b98c8fe1 to your computer and use it in GitHub Desktop.
(deftest test-pick-n-of-each
(let [pick-n-of-each (comp vec algo/pick-n-of-each)]
(testing "Varying number of each group"
(are
[expected n] (= expected (pick-n-of-each n (range) [:a :b]))
[] 0
[[0 :a] [1 :b]] 1
[[0 :a] [1 :a] [2 :b] [3 :b]] 2
))
(testing "Varying number of groups"
(are
[expected groups] (= expected (pick-n-of-each 2 (range) groups))
[] []
[[0 :a] [1 :a]] [:a]
))
(testing "No elements to choose from"
(is
(= [] (pick-n-of-each 1 [] [:a]))
))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment