aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2023-02-23 02:18:57 +0100
committerHugo Hörnquist <hugo@lysator.liu.se>2023-02-23 04:03:36 +0100
commit5ab726d27c2a300fefbcc843ad01a7c04590ff15 (patch)
treedb9e7bc8e047fdc5242a9b7c55883c6892770963 /tests
parentExtend `for'-macro to allow improper list elements. (diff)
downloadcalp-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 'tests')
-rw-r--r--tests/test/util.scm19
-rwxr-xr-xtests/validate-html/run-validator.scm2
2 files changed, 20 insertions, 1 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)))
diff --git a/tests/validate-html/run-validator.scm b/tests/validate-html/run-validator.scm
index bd96c32d..0c4ee0bc 100755
--- a/tests/validate-html/run-validator.scm
+++ b/tests/validate-html/run-validator.scm
@@ -80,6 +80,6 @@ exec $GUILE -e main -s "$0" -- "$@"
(begin
(for-each (lambda (group)
(format #t "~a~%" (-> group car (assoc-ref 'url) car))
- (for-each display-entry (cadr group)))
+ (for-each display-entry (cdr group)))
(group-by-file filtered-data))
(exit 1)))))