Files
rose-ash/lib/haskell/tests/program-uniquewords.sx
giles 5605fe1cc2
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 36s
haskell: Phase 12 conformance — uniquewords.hs (4/4) + setops.hs (8/8), Phase 12 complete
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-07 11:45:21 +00:00

36 lines
1.1 KiB
Plaintext

;; uniquewords.hs — count unique words using Data.Set.
;;
;; Exercises Phase 12: `import qualified Data.Set as Set`, `Set.empty`,
;; `Set.insert`, `Set.size`, `foldl`.
(define
hk-uniquewords-source
"import qualified Data.Set as Set\n\naddWord s w = Set.insert w s\n\nuniqueWords ws = foldl addWord Set.empty ws\n\nresult = uniqueWords [\"the\", \"cat\", \"the\", \"dog\", \"the\", \"cat\"]\n")
(hk-test
"uniquewords.hs — unique count = 3"
(hk-deep-force
(hk-run (str hk-uniquewords-source "main = Set.size result\n")))
3)
(hk-test
"uniquewords.hs — \"the\" present"
(hk-deep-force
(hk-run (str hk-uniquewords-source "main = Set.member \"the\" result\n")))
(list "True"))
(hk-test
"uniquewords.hs — \"missing\" absent"
(hk-deep-force
(hk-run (str hk-uniquewords-source "main = Set.member \"missing\" result\n")))
(list "False"))
(hk-test
"uniquewords.hs — empty list yields empty set"
(hk-deep-force
(hk-run
"import qualified Data.Set as Set\nmain = Set.size (foldl (\\s w -> Set.insert w s) Set.empty [])"))
0)
{:fails hk-test-fails :pass hk-test-pass :fail hk-test-fail}