diff options
Diffstat (limited to 'specs')
| -rw-r--r-- | specs/Main.hs | 8 | ||||
| -rw-r--r-- | specs/Specs/KeySequenceSpec.hs | 54 |
2 files changed, 62 insertions, 0 deletions
diff --git a/specs/Main.hs b/specs/Main.hs new file mode 100644 index 0000000..335407f --- /dev/null +++ b/specs/Main.hs @@ -0,0 +1,8 @@ +module Main (main) where + +import qualified Specs.KeySequenceSpec +import Test.Hspec (hspec) + +main :: IO () +main = hspec $ do + Specs.KeySequenceSpec.test diff --git a/specs/Specs/KeySequenceSpec.hs b/specs/Specs/KeySequenceSpec.hs new file mode 100644 index 0000000..d094741 --- /dev/null +++ b/specs/Specs/KeySequenceSpec.hs @@ -0,0 +1,54 @@ +module Specs.KeySequenceSpec where + +import Chelleport.KeySequence (findMatchPosition, generateKeyCells, nextChars) +import Test.Hspec + +test = do + describe "#nextChars" $ do + it "filters key sequence and returns next characters" $ do + nextChars "AB" [["XYZ", "ABC"], ["AMK", "BBL", "ABD"]] + `shouldBe` Just "CD" + nextChars "A" [["XYZ", "ABC"], ["AMK", "BBL", "ABD"]] + `shouldBe` Just "BM" + + context "when exact match is present" $ do + it "returns next characters" $ do + nextChars "ABD" [["XYZ", "ABC"], ["AMK", "BBL", "ABD"]] + `shouldBe` Just "" + + context "when there are no matches" $ do + it "returns nothing" $ do + nextChars "FOO" [["XYZ", "ABC"], ["AMK", "BBL", "ABD"]] + `shouldBe` Nothing + + describe "#generateKeyCells" $ do + it "generates grid of key sequences" $ do + generateKeyCells (4, 4) "ABCDEF" + `shouldBe` [ ["HKA", "HKB", "LKA", "LKB"], + ["HKC", "HKD", "LKC", "LKD"], + ["HJA", "HJB", "LJA", "LJB"], + ["HJC", "HJD", "LJC", "LJD"] + ] + context "when the the keys set is too short" $ do + it "cycles back to first character" $ do + generateKeyCells (4, 4) "AB" + `shouldBe` [ ["HKA", "HKB", "LKA", "LKB"], + ["HKA", "HKB", "LKA", "LKB"], + ["HJA", "HJB", "LJA", "LJB"], + ["HJA", "HJB", "LJA", "LJB"] + ] + + describe "#findMatchPosition" $ do + it "returns the position of the matching key sequence" $ do + findMatchPosition "ABD" [["XYZ", "ABC"], ["AMK", "BBL", "ABD"]] + `shouldBe` Just (1, 2) + + context "when sequence is incomplete" $ do + it "returns nothing" $ do + findMatchPosition "AB" [["XYZ", "ABC"], ["AMK", "BBL", "ABD"]] + `shouldBe` Nothing + + context "when there are no matches" $ do + it "returns nothing" $ do + findMatchPosition "FOO" [["XYZ", "ABC"], ["AMK", "BBL", "ABD"]] + `shouldBe` Nothing |
