about summary refs log tree commit diff
path: root/scratch/brilliant/Spec.hs
blob: c55da72d0c374ec98fa83c42de4823e51f75a51c (plain) (blame)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
--------------------------------------------------------------------------------
module Spec where
--------------------------------------------------------------------------------
import Test.Hspec
import Test.QuickCheck
import Control.Exception (evaluate)
import Keyboard (Keyboard(..))
import Transforms (Transform(..))

import qualified App
import qualified Keyboard
import qualified Transforms
import qualified Utils
--------------------------------------------------------------------------------

main :: IO ()
main = hspec $ do
  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
             ]

    it "returns Nothing when the input is invalid" $ do
      Transforms.fromString "potato" == Nothing

    it "return Nothing when the input is valid except for the end" $ do
      Transforms.fromString "HVS10potato" == Nothing

  describe "App.transform" $ do
    it "flips a keyboard horizontally" $ do
      App.transform HorizontalFlip Keyboard.qwerty == do
        Keyboard [ reverse ['1','2','3','4','5','6','7','8','9','0']
                 , reverse ['Q','W','E','R','T','Y','U','I','O','P']
                 , reverse ['A','S','D','F','G','H','J','K','L',';']
                 , reverse ['Z','X','C','V','B','N','M',',','.','/']
                 ]

    it "flips a keyboard vertically" $ do
      App.transform VerticalFlip Keyboard.qwerty == do
        Keyboard $ reverse [ ['1','2','3','4','5','6','7','8','9','0']
                           , ['Q','W','E','R','T','Y','U','I','O','P']
                           , ['A','S','D','F','G','H','J','K','L',';']
                           , ['Z','X','C','V','B','N','M',',','.','/']
                           ]

    it "shifts a keyboard N times" $ do
      App.transform (Shift 2) Keyboard.qwerty == do
        Keyboard $ [ Utils.rotate 2 ['1','2','3','4','5','6','7','8','9','0']
                   , Utils.rotate 2 ['Q','W','E','R','T','Y','U','I','O','P']
                   , Utils.rotate 2 ['A','S','D','F','G','H','J','K','L',';']
                   , Utils.rotate 2 ['Z','X','C','V','B','N','M',',','.','/']
                   ]

    it "shifts negative amounts" $ do
      App.transform (Shift (-3)) Keyboard.qwerty == do
        Keyboard $ [ Utils.rotate (-3) ['1','2','3','4','5','6','7','8','9','0']
                   , Utils.rotate (-3) ['Q','W','E','R','T','Y','U','I','O','P']
                   , Utils.rotate (-3) ['A','S','D','F','G','H','J','K','L',';']
                   , Utils.rotate (-3) ['Z','X','C','V','B','N','M',',','.','/']
                   ]