[functional-tests] Tests are now identified by a list of symbols.

Improved formatting too.
This commit is contained in:
Joe Thornber
2017-08-17 11:23:43 +01:00
parent 08ebf0aa8a
commit 66647ae549
3 changed files with 105 additions and 57 deletions

View File

@@ -1,7 +1,15 @@
(library
(list-utils)
(export tails intersperse iterate accumulate)
(import (rnrs))
(export tails
intersperse
iterate
comparing
list-group-by
accumulate)
(import (rnrs)
(srfi s8 receive))
(define (tails xs)
(if (null? xs)
@@ -22,6 +30,19 @@
'()
(cons (fn) (loop (- count 1))))))
(define (comparing cmp key)
(lambda (x y)
(cmp (key x) (key y))))
;; Assumes the list is already sorted
(define (list-group-by pred xs)
(if (null? xs)
'()
(let ((fst (car xs)))
(receive (g1 gs) (partition (lambda (x) (pred fst x)) (cdr xs))
(cons (cons fst g1)
(list-group-by pred gs))))))
;; calculates a running total for a list. Returns a list.
(define (accumulate xs)
(let loop ((xs xs) (total 0))