summaryrefslogtreecommitdiff
path: root/spellcheck/spellcheck-test.scm
diff options
context:
space:
mode:
authorbd <bdunahu@operationnull.com>2024-05-20 01:07:13 -0600
committerbd <bdunahu@operationnull.com>2024-05-20 14:59:16 -0600
commit5df534c4e3893a9f7a4f528746eca98d7a012736 (patch)
tree06ddcea130301a55d9b7f21a5c72d27ec3b4d281 /spellcheck/spellcheck-test.scm
parentde8ec8026b3fbf60cfa95ef1c48ad53e1b922d38 (diff)
Add dictionary code and tests
Diffstat (limited to 'spellcheck/spellcheck-test.scm')
-rw-r--r--spellcheck/spellcheck-test.scm57
1 files changed, 57 insertions, 0 deletions
diff --git a/spellcheck/spellcheck-test.scm b/spellcheck/spellcheck-test.scm
new file mode 100644
index 0000000..8030c41
--- /dev/null
+++ b/spellcheck/spellcheck-test.scm
@@ -0,0 +1,57 @@
+(use-modules (srfi srfi-64)
+ (hasher dictionary))
+
+(define simple-dict (create-dictionary '("word")))
+(define complex-dict (create-dictionary '("Again" "the" "thirst"
+ "quencher" "of" "wolves"
+ "embarked" "on" "a" "well"
+ "prepared" "expedition"
+ "eastward" "the" "generous"
+ "ruler" "moved" "the" "bitter"
+ "heart" "of" "the" "snake"
+ "across" "the" "fire")))
+
+(test-begin "harness")
+
+
+(test-assert "create-dictionary returns hashtable"
+ (hash-table?
+ (create-dictionary '())))
+
+(define dict (create-dictionary '("word")))
+
+(test-equal "list-keys-single"
+ '("word")
+ (dict-keys-ref simple-dict))
+
+(test-equal "count-values-single"
+ 1
+ (dict-values-ref simple-dict))
+
+
+(test-equal "retrieve single"
+ 1
+ (dict-occur-ref complex-dict "wolves"))
+
+(test-equal "retrieve double"
+ 2
+ (dict-occur-ref complex-dict "of"))
+
+(test-equal "retrieve quintuple"
+ 5
+ (dict-occur-ref complex-dict "the"))
+
+(test-equal "retrieve zero"
+ 0
+ (dict-occur-ref complex-dict "king"))
+
+(test-equal "list-keys-sentence"
+ '("Again" "a" "across" "bitter" "eastward" "embarked" "expedition" "fire" "generous" "heart" "moved" "of" "on" "prepared" "quencher" "ruler" "snake" "the" "thirst" "well" "wolves")
+ (sort (dict-keys-ref complex-dict) string<?))
+
+(test-equal "count-values-sentence"
+ 26
+ (dict-values-ref complex-dict))
+
+
+(test-end "harness")