From 5dd73a1f072dde69574da5ee9cf10ff81dd0408f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Mon, 16 Oct 2023 15:10:34 +0200 Subject: Add documentation and tests for table. --- tests/unit/util/table.scm | 48 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 tests/unit/util/table.scm (limited to 'tests') diff --git a/tests/unit/util/table.scm b/tests/unit/util/table.scm new file mode 100644 index 00000000..564dff74 --- /dev/null +++ b/tests/unit/util/table.scm @@ -0,0 +1,48 @@ +(define-module (test table) + :use-module (srfi srfi-64) + :use-module (srfi srfi-88) + :use-module ((hnh util) :select (->)) + :use-module (hnh util table)) + +(test-expect-fail "Equivalent tables are equal") + +(define t (table)) + +(test-assert "Empty tables are empty" (null? (table->list t))) + +(test-equal "Adding elements work" + '((a . 10) (b . 20)) + (-> t + (table-put 'a 10) + (table-put 'b 20) + table->list)) + +(test-assert "Original table is unchanged" + (null? (table->list t))) + +(test-equal "Insertion order doesn't matter, when serializing to lists" + (-> t + (table-put 'a 10) + (table-put 'b 20) + table->list) + (-> t + (table-put 'b 20) + (table-put 'a 10) + table->list)) + +;;; TODO this doesn't work, since the trees don't rebalance +(test-equal "Equivalent tables are equal" + (-> t + (table-put 'a 10) + (table-put 'b 20) + (table-put 'c 30)) + (-> t + (table-put 'c 30) + (table-put 'b 20) + (table-put 'a 10))) + +;;; TODO test table-get +;; (table-get t 'key) +;; (table-put t 'key value) + +'((hnh util table)) -- cgit v1.2.3