diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2023-02-23 02:18:57 +0100 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2023-02-23 04:03:36 +0100 |
commit | 5ab726d27c2a300fefbcc843ad01a7c04590ff15 (patch) | |
tree | db9e7bc8e047fdc5242a9b7c55883c6892770963 /tests/test/util.scm | |
parent | Extend `for'-macro to allow improper list elements. (diff) | |
download | calp-5ab726d27c2a300fefbcc843ad01a7c04590ff15.tar.gz calp-5ab726d27c2a300fefbcc843ad01a7c04590ff15.tar.xz |
Change group-by to return direct pairs.
Each value in the return of group-by must have exactly two values, so
cons pairs (instead of lists) is much better.
Diffstat (limited to '')
-rw-r--r-- | tests/test/util.scm | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/test/util.scm b/tests/test/util.scm index 2a171d12..9a203f50 100644 --- a/tests/test/util.scm +++ b/tests/test/util.scm @@ -132,6 +132,25 @@ ;; TODO assq-limit ? +(test-group "group by" + ;; Extra roundabout tests since groups-by doesn't guarantee order of the keys + (test-group "Two simple groups" + (let ((groups (group-by even? (iota 10)))) + (test-assert (lset= eq? '(#f #t) (map car groups))) + (test-assert (lset= = '(0 2 4 6 8) (assq-ref groups #t))) + (test-assert (lset= = '(1 3 5 7 9) (assq-ref groups #f))))) + + (test-group "Identity groups" + (let ((groups (group-by identity (iota 5)))) + (test-assert "Correct keys" + (lset= = (iota 5) (map car groups))) + (test-group "Correct amount in each group" + (for-each (lambda (g) (test-equal 1 (length (cdr g)))) groups)))) + + (test-equal "Null case" + '() + (group-by (lambda _ (/ 0)) '()))) + (test-equal "->" 9 (-> 1 (+ 2) (* 3))) (test-equal "-> order dependant" -1 (-> 1 (- 2))) (test-equal "->> order dependant" 1 (->> 1 (- 2))) |