-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_problem_2.cljc
More file actions
44 lines (38 loc) · 1.68 KB
/
test_problem_2.cljc
File metadata and controls
44 lines (38 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
(ns cljs-solutions.test-problem_2
[:require
[cljs-solutions.problem_2 :as p2]
#?(:clj [clojure.test :refer [deftest is are]]
:cljs [cljs.test :refer-macros [deftest is are]])])
(deftest test-subseqs-by-count
; Function subseqs-by-count is private, but the var #'p2/subseqs-by-count
; can be looked up and dereferenced.
(are [xs result] (= result (@#'p2/subseqs-by-count #{(seq xs)}))
[] nil
"" nil
[:a] [#{[:a]}]
[:a :b] [#{[:a :b]} #{[:a][:b]}]
"abc" [#{(seq "abc")}
#{(seq "ab") (seq "bc")}
#{(seq "a") (seq "b") (seq "c")}]))
(deftest test-common-subseqs
(are [strs result] (= (map (comp set (partial map seq))
result)
(apply p2/common-subseqs strs))
[""] []
["" ""] []
["a" ""] []
["ab" "cd"] []
["ab"] [["ab"] ["a" "b"]]
["a" "ab"] [["a"]]
["ab" "abc" "bcd"] [["b"]]
["abc" "bcd" "cde"] [["c"]]
["abcd" "abc" "abcde"] [["abc"]["ab" "bc"]["a" "b" "c"]]))
(deftest test-maximal-common
(is (= (p2/maximal-common-subseqs "abcde" "eabcd" "deabc" "bcab" "abc")
#{[\b \c] [\a \b]}))
(is (= (set (p2/maximal-common-substrings
"abcde" "eabcd" "deabc" "bcab" "abc"))
#{"bc" "ab"}))
(is (= (set (p2/maximal-common-substrings-ignoring-case
"AbcDe" "Eabcd" "deaBc" "bcab" "abc"))
#{"BC" "AB"})))