2020-08-05 22:37:08 +02:00
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
module Spec where
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
import Test.Hspec
|
2020-08-12 12:24:20 +02:00
|
|
|
import Test.QuickCheck
|
2020-08-06 00:20:18 +02:00
|
|
|
import Keyboard (Keyboard(..))
|
2020-08-05 23:54:50 +02:00
|
|
|
import Transforms (Transform(..))
|
|
|
|
|
2020-08-06 00:20:18 +02:00
|
|
|
import qualified App
|
2020-08-05 23:54:50 +02:00
|
|
|
import qualified Keyboard
|
|
|
|
import qualified Transforms
|
2020-08-06 00:20:18 +02:00
|
|
|
import qualified Utils
|
2020-08-05 22:37:08 +02:00
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
main :: IO ()
|
|
|
|
main = hspec $ do
|
2020-08-05 23:54:50 +02:00
|
|
|
describe "Keyboard.print" $ do
|
|
|
|
it "pretty-prints the keyboard" $ do
|
|
|
|
show Keyboard.qwerty == "[1][2][3][4][5][6][7][8][9][0]\n[Q][W][E][R][T][Y][U][I][O][P]\n[A][S][D][F][G][H][J][K][L][;]\n[Z][X][C][V][B][N][M][,][.][/]"
|
|
|
|
|
|
|
|
describe "Transforms.fromString" $ do
|
|
|
|
it "successfully parses a string of commands" $ do
|
|
|
|
Transforms.fromString "HHVS-12VHVHS3" ==
|
|
|
|
Just [ HorizontalFlip
|
|
|
|
, HorizontalFlip
|
|
|
|
, VerticalFlip
|
|
|
|
, Shift (-12)
|
|
|
|
, VerticalFlip
|
|
|
|
, HorizontalFlip
|
|
|
|
, VerticalFlip
|
|
|
|
, HorizontalFlip
|
|
|
|
, Shift 3
|
|
|
|
]
|
2020-08-05 22:37:08 +02:00
|
|
|
|
2020-08-05 23:54:50 +02:00
|
|
|
it "returns Nothing when the input is invalid" $ do
|
|
|
|
Transforms.fromString "potato" == Nothing
|
2020-08-05 22:37:08 +02:00
|
|
|
|
2020-08-05 23:54:50 +02:00
|
|
|
it "return Nothing when the input is valid except for the end" $ do
|
|
|
|
Transforms.fromString "HVS10potato" == Nothing
|
2020-08-06 00:20:18 +02:00
|
|
|
|
|
|
|
describe "App.transform" $ do
|
2020-08-12 12:24:20 +02:00
|
|
|
it "flips any keyboard horizontally" $ do
|
|
|
|
property $ \first second third fourth ->
|
|
|
|
App.transform (Keyboard [first, second, third, fourth]) HorizontalFlip == do
|
|
|
|
Keyboard [ reverse first
|
|
|
|
, reverse second
|
|
|
|
, reverse third
|
|
|
|
, reverse fourth
|
|
|
|
]
|
|
|
|
|
|
|
|
it "flips any keyboard vertically" $ do
|
|
|
|
property $ \first second third fourth ->
|
|
|
|
App.transform (Keyboard [first, second, third, fourth]) VerticalFlip == do
|
|
|
|
Keyboard $ reverse [first, second, third, fourth]
|
|
|
|
|
|
|
|
it "shifts any keyboard" $ do
|
|
|
|
property $ \first second third fourth n ->
|
|
|
|
App.transform (Keyboard [first, second, third, fourth]) (Shift n) == do
|
|
|
|
Keyboard $ [ Utils.rotate n first
|
|
|
|
, Utils.rotate n second
|
|
|
|
, Utils.rotate n third
|
|
|
|
, Utils.rotate n fourth
|
|
|
|
]
|
|
|
|
|
|
|
|
it "flips a QWERTY keyboard horizontally" $ do
|
2020-08-06 00:30:25 +02:00
|
|
|
App.transform Keyboard.qwerty HorizontalFlip == do
|
2020-08-12 12:07:37 +02:00
|
|
|
Keyboard [ ['0','9','8','7','6','5','4','3','2','1']
|
|
|
|
, ['P','O','I','U','Y','T','R','E','W','Q']
|
|
|
|
, [';','L','K','J','H','G','F','D','S','A']
|
|
|
|
, ['/','.',',','M','N','B','V','C','X','Z']
|
2020-08-06 00:20:18 +02:00
|
|
|
]
|
|
|
|
|
|
|
|
it "flips a keyboard vertically" $ do
|
2020-08-06 00:30:25 +02:00
|
|
|
App.transform Keyboard.qwerty VerticalFlip == do
|
2020-08-12 12:07:37 +02:00
|
|
|
Keyboard $ [ ['Z','X','C','V','B','N','M',',','.','/']
|
|
|
|
, ['A','S','D','F','G','H','J','K','L',';']
|
|
|
|
, ['Q','W','E','R','T','Y','U','I','O','P']
|
|
|
|
, ['1','2','3','4','5','6','7','8','9','0']
|
|
|
|
]
|
2020-08-06 00:20:18 +02:00
|
|
|
|
2020-08-12 12:07:37 +02:00
|
|
|
it "shifts a keyboard left N times" $ do
|
2020-08-06 00:30:25 +02:00
|
|
|
App.transform Keyboard.qwerty (Shift 2) == do
|
2020-08-12 12:07:37 +02:00
|
|
|
Keyboard $ [ ['3','4','5','6','7','8','9','0','1','2']
|
|
|
|
, ['E','R','T','Y','U','I','O','P','Q','W']
|
|
|
|
, ['D','F','G','H','J','K','L',';','A','S']
|
|
|
|
, ['C','V','B','N','M',',','.','/','Z','X']
|
2020-08-06 00:20:18 +02:00
|
|
|
]
|
|
|
|
|
2020-08-12 12:07:37 +02:00
|
|
|
it "shifts right negative amounts" $ do
|
2020-08-06 00:30:25 +02:00
|
|
|
App.transform Keyboard.qwerty (Shift (-3)) == do
|
2020-08-12 12:07:37 +02:00
|
|
|
Keyboard $ [ ['8','9','0','1','2','3','4','5','6','7']
|
|
|
|
, ['I','O','P','Q','W','E','R','T','Y','U']
|
|
|
|
, ['K','L',';','A','S','D','F','G','H','J']
|
|
|
|
, [',','.','/','Z','X','C','V','B','N','M']
|
2020-08-06 00:20:18 +02:00
|
|
|
]
|
2020-08-06 01:15:31 +02:00
|
|
|
|
|
|
|
describe "Transforms.optimize" $ do
|
|
|
|
it "removes superfluous horizontal transformations" $ do
|
|
|
|
Transforms.optimize [HorizontalFlip, HorizontalFlip] == []
|
|
|
|
|
|
|
|
it "removes superfluous vertical transformations" $ do
|
|
|
|
Transforms.optimize [VerticalFlip, VerticalFlip] == []
|