aboutsummaryrefslogtreecommitdiffstats
path: root/sort-test.csc
diff options
context:
space:
mode:
authorRose Hogenson <rhogenson@posteo.net>2022-01-09 16:20:43 -0800
committerRose Hogenson <rhogenson@posteo.net>2022-01-09 16:20:43 -0800
commitf06966df463bdba5912b999bcb6ab0badb83a561 (patch)
tree325be54ab153da135db02498feafcea9cc3ea1aa /sort-test.csc
parentd579fede001a09d3a4047a8df71be406ff30e95e (diff)
downloadchromatopelma-f06966df463bdba5912b999bcb6ab0badb83a561.tar.zst
Redo the testing framework.
We can lean more on the power of scheme to make the testing framework a little less verbose.
Diffstat (limited to 'sort-test.csc')
-rw-r--r--sort-test.csc70
1 files changed, 30 insertions, 40 deletions
diff --git a/sort-test.csc b/sort-test.csc
index b922484..dec2a53 100644
--- a/sort-test.csc
+++ b/sort-test.csc
@@ -1,45 +1,35 @@
(import (scheme base)
(only (csc testing)
- define-test
- errorf)
+ assert-equal
+ test)
(csc sort))
-(define-test (test-sort t)
- (define-record-type <test-case>
- (test-case desc xs want)
- test-case?
- (desc desc)
- (xs xs)
- (want want))
- (let ((tests (list
- (test-case
- "ten elem"
- '(9 4 5 100 3 2 4 6 0 -2)
- '(-2 0 2 3 4 4 5 6 9 100))
- (test-case
- "empty"
- '()
- '())
- (test-case
- "singleton"
- '(1)
- '(1))
- (test-case
- "two"
- '(2 1)
- '(1 2))
- (test-case
- "reversed"
- '(20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1)
- '(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20))
- (test-case
- "already sorted"
- '(1 2 3 4 5 6 7 8 9 10)
- '(1 2 3 4 5 6 7 8 9 10)))))
- (for-each
- (lambda (tc)
- (let ((got (sort (lambda (x1 x2) (< x1 x2)) (xs tc))))
- (unless (equal? got (want tc))
- (errorf t "(sort {}) = {}, want {}." (xs tc) got (want tc)))))
- tests)))
+(test sort-ten-elem
+ (assert-equal
+ '(-2 0 2 3 4 4 5 6 9 100)
+ (sort < '(9 4 5 100 3 2 4 6 0 -2))))
+
+
+(test sort-empty
+ (assert-equal '() (sort < '())))
+
+
+(test sort-singleton
+ (assert-equal '(1) (sort < '(1))))
+
+
+(test sort-two
+ (assert-equal '(1 2) (sort < '(2 1))))
+
+
+(test sort-reversed
+ (assert-equal
+ '(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20)
+ (sort < '(20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1))))
+
+
+(test sort-already-sorted
+ (assert-equal
+ '(1 2 3 4 5 6 7 8 9 10)
+ (sort < '(1 2 3 4 5 6 7 8 9 10))))