From bee0febb5d98f0993a7a3bd175046f4fbf9c8eec Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Sun, 15 Dec 2024 19:31:47 +0530 Subject: Generate random key sequences with lcg --- specs/Specs/KeySequenceSpec.hs | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) (limited to 'specs/Specs') diff --git a/specs/Specs/KeySequenceSpec.hs b/specs/Specs/KeySequenceSpec.hs index 707646d..2efbece 100644 --- a/specs/Specs/KeySequenceSpec.hs +++ b/specs/Specs/KeySequenceSpec.hs @@ -1,6 +1,7 @@ module Specs.KeySequenceSpec where -import Chelleport.KeySequence (findMatchPosition, generateKeyCells, nextChars) +import Chelleport.KeySequence (findMatchPosition, generateGrid, nextChars) +import qualified Debug.Trace as Debug import Test.Hspec test = do @@ -22,22 +23,15 @@ test = do nextChars "FOO" [["XYZ", "ABC"], ["AMK", "BBL", "ABD"]] `shouldBe` Nothing - describe "#generateKeyCells" $ do + describe "#generateGrid" $ 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"] - ] + generateGrid 0 (4, 4) "ABCDEF" + `shouldBe` Just [["AE", "BD", "CC", "BB"], ["AC", "FD", "EE", "EC"], ["FB", "EA", "DF", "DD"], ["CA", "DB", "CE", "BF"]] + 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"] - ] + generateGrid 0 (4, 4) "AB" + `shouldBe` Nothing describe "#findMatchPosition" $ do it "returns the position of the matching key sequence" $ do -- cgit v1.3.1