From 3ff7aac2d2eb2cbf2f854793fc0d7bc6f1f7d927 Mon Sep 17 00:00:00 2001 From: Rose Hogenson Date: Sun, 9 Jan 2022 08:40:09 -0800 Subject: 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. --- sort-test.csc | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 sort-test.csc (limited to 'sort-test.csc') 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 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))) -- cgit v1.3.1