Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d1b2ddc351 |
@@ -23,6 +23,13 @@
|
|||||||
(map second)
|
(map second)
|
||||||
(into [])))
|
(into [])))
|
||||||
|
|
||||||
|
(defn get-all-permutation-for-block
|
||||||
|
"Return a vector for all possible blocks that can be made from a vector of symbols."
|
||||||
|
[symbols]
|
||||||
|
(->> (comb/permutations symbols)
|
||||||
|
(map cs/join)
|
||||||
|
(into [])))
|
||||||
|
|
||||||
(defn get-possible-keys
|
(defn get-possible-keys
|
||||||
"Return possible keys for a possible key vector. For example, if you have a map: {\\a [\\a \\b \\c] \\b [\\b \\c] \\c [\\a \\c]}, then the vector is [[\\a \\b \\c] [\\b \\c] [\\a \\c]] and keys (\"aba\" \"abc\" ...)."
|
"Return possible keys for a possible key vector. For example, if you have a map: {\\a [\\a \\b \\c] \\b [\\b \\c] \\c [\\a \\c]}, then the vector is [[\\a \\b \\c] [\\b \\c] [\\a \\c]] and keys (\"aba\" \"abc\" ...)."
|
||||||
[possible-key-vector]
|
[possible-key-vector]
|
||||||
|
|||||||
@@ -14,12 +14,19 @@
|
|||||||
{\a [\a \b] \c [\b \a] \b [\a \c]} "abc" [[\a \b] [\a \c] [\b \a]])))
|
{\a [\a \b] \c [\b \a] \b [\a \c]} "abc" [[\a \b] [\a \c] [\b \a]])))
|
||||||
|
|
||||||
(deftest get-possible-key-vector-from-reversed-count-map-test
|
(deftest get-possible-key-vector-from-reversed-count-map-test
|
||||||
(testing ""
|
(testing "The block order must be in descending order"
|
||||||
(are [reversed-count-map expected-key-vector]
|
(are [reversed-count-map expected-key-vector]
|
||||||
(= expected-key-vector (get-possible-key-vector-from-reversed-count-map reversed-count-map))
|
(= expected-key-vector (get-possible-key-vector-from-reversed-count-map reversed-count-map))
|
||||||
{1 [\a \c] 2 [\b]} [[\b] [\a \c]]
|
{1 [\a \c] 2 [\b]} [[\b] [\a \c]]
|
||||||
{2 [\a] 1 [\b] 3 [\c]} [[\c] [\a] [\b]])))
|
{2 [\a] 1 [\b] 3 [\c]} [[\c] [\a] [\b]])))
|
||||||
|
|
||||||
|
(deftest get-all-permutation-for-block-test
|
||||||
|
(testing "It must return all permutations"
|
||||||
|
(are [symbols expected-permutations]
|
||||||
|
(= expected-permutations (get-all-permutation-for-block symbols))
|
||||||
|
[\a \b] ["ab" "ba"]
|
||||||
|
[\a \b \c] ["abc" "acb" "bac" "bca" "cab" "cba"])))
|
||||||
|
|
||||||
(deftest get-possible-keys-test
|
(deftest get-possible-keys-test
|
||||||
(testing "The keys must be the all combinations"
|
(testing "The keys must be the all combinations"
|
||||||
(are [possible-keys-vector expected-keys]
|
(are [possible-keys-vector expected-keys]
|
||||||
|
|||||||
Reference in New Issue
Block a user