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. --- hash-map-test.csc | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 hash-map-test.csc (limited to 'hash-map-test.csc') diff --git a/hash-map-test.csc b/hash-map-test.csc new file mode 100644 index 0000000..8f51dfa --- /dev/null +++ b/hash-map-test.csc @@ -0,0 +1,98 @@ +(import (scheme base) + (only (csc sort) sort) + (only (csc testing) + define-test + errorf + subtest) + (csc hash-map)) + + +(define (hash-symbol s) + (hash-bytevector (string->utf8 (symbol->string s)))) + + +(define (symbolstring s1) (symbol->string s2))) + + +(define-test (test-hash-map->alist t) + (define-record-type + (test-case desc vals) + test-case? + (desc desc) + (vals vals)) + (let ((tests (list + (test-case + "singleton" + '((a . 1))) + (test-case + "two" + '((a . 1) (b . 2))) + (test-case + "longer" + '((a . 1) (b . 2) (c . 3) (d . 4) (e . 5) (f . 6)))))) + (for-each + (lambda (tc) + (subtest t (desc tc) + (let* ((m (alist->hash-map hash-symbol symbolalist m))) + (unless (equal? + (sort + (lambda (x1 x2) (symbolalist {}) = {}, want {}." m got (vals tc)))))) + tests))) + + +(define-test (test-alist->hash-map t) + (define-record-type + (test-case desc vals want) + test-case? + (desc desc) + (vals vals) + (want want)) + (let ((tests (list + (test-case + "singleton" + '((a . 1)) + '((a . 1))) + (test-case + "two" + '((a . 1) (b . 2)) + '((a . 1) (b . 2))) + (test-case + "larger" + '((m . 1) (n . 2) (q . 3) (f . 5) (n . 7) (x . 8)) + '((f . 5) (m . 1) (n . 7) (q . 3) (x . 8))) + (test-case + "in-order" + '((a . ()) (b . ()) (c . ()) (d . ()) (e . ()) (f . ()) (g . ()) (h . ())) + '((a . ()) (b . ()) (c . ()) (d . ()) (e . ()) (f . ()) (g . ()) (h . ()))) + (test-case + "reversed" + '((h . ()) (g . ()) (f . ()) (e . ()) (d . ()) (c . ()) (b . ()) (a . ())) + '((a . ()) (b . ()) (c . ()) (d . ()) (e . ()) (f . ()) (g . ()) (h . ()))) + (test-case + "overwrite" + '((a . 1) (a . 2)) + '((a . 2))) + (test-case + "alternating" + '((h . ()) (g . ()) (i . ()) (f . ()) (j . ()) (e . ()) (k . ()) (d . ()) (l . ()) (c . ())) + '((c . ()) (d . ()) (e . ()) (f . ()) (g . ()) (h . ()) (i . ()) (j . ()) (k . ()) (l . ())))))) + (for-each + (lambda (tc) + (subtest t (desc tc) + (let ((got (alist->hash-map hash-symbol symbolalist got)) + (sort + (lambda (x1 x2) (symbolhash-map {}) = {}, want {}." (vals tc) (hash-map->alist got) (want tc)))))) + tests))) -- cgit v1.3.1