diff options
| author | Rose Hogenson <rhogenson@posteo.net> | 2022-01-09 08:40:09 -0800 |
|---|---|---|
| committer | Rose Hogenson <rhogenson@posteo.net> | 2022-01-09 08:40:09 -0800 |
| commit | 3ff7aac2d2eb2cbf2f854793fc0d7bc6f1f7d927 (patch) | |
| tree | cef8ca0e77c40a70daaca40af25572437d563105 /sort-test.csc | |
| download | chromatopelma-3ff7aac2d2eb2cbf2f854793fc0d7bc6f1f7d927.tar.zst | |
Initial commit.
Not sure if everything here will be needed eventually, but we have a
working bytecode interpreter. Next I will write the linker, then the
core compiler, and finish with the macro expander.
Diffstat (limited to 'sort-test.csc')
| -rw-r--r-- | sort-test.csc | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/sort-test.csc b/sort-test.csc new file mode 100644 index 0000000..b922484 --- /dev/null +++ b/sort-test.csc @@ -0,0 +1,45 @@ +(import (scheme base) + (only (csc testing) + define-test + errorf) + (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))) |
