implemented bit flipping

This commit is contained in:
2024-08-01 20:31:25 -04:00
parent 2a46e085d5
commit 14867b54b0
5 changed files with 55 additions and 6 deletions

View File

@@ -33,6 +33,7 @@ spec = describe "Actions" $ do
moveDownSpec
moveLeftSpec
moveRightSpec
flipBitSpec
moveUpSpec :: Spec
moveUpSpec = describe "moveUp" $ mapM_
@@ -102,4 +103,23 @@ moveRightSpec = describe "moveRight" $ mapM_
& rowNum .~ 1
& colNum .~ 2
flipBitSpec :: Spec
flipBitSpec = describe "flipBit" $ mapM_
( \(desc, state, expected) -> context desc $ let
actual = flipBit state
in it ("should be " ++ show expected) $
actual `shouldBe` expected
)
[ ( "turn on", unflipped, flipped )
, ( "turn off", flipped, unflipped )
, ( "non-edit mode", nonEdit, nonEdit )
] where
nonEdit = initialState & hammingCode .~ 0x3c5a
unflipped = nonEdit & appMode .~ EditMode
( initialEditor
& rowNum .~ 1
& colNum .~ 3
)
flipped = unflipped & hammingCode .~ 0x3cda
--jl

View File

@@ -29,8 +29,9 @@ import Hamming.App.Types
import Hamming.App.Util
spec :: Spec
spec = describe "Util"
spec = describe "Util" $ do
getLocationSpec
bitmaskSpec
getLocationSpec :: Spec
getLocationSpec = describe "getLocation" $ mapM_
@@ -50,4 +51,14 @@ getLocationSpec = describe "getLocation" $ mapM_
)
l = Location (4, 3)
bitmaskSpec :: Spec
bitmaskSpec = describe "bitmask" $ let
s = initialEditor
& rowNum .~ 1
& colNum .~ 2
actual = bitmask s
expected = 0x0040
in it ("should be " ++ show expected) $
actual `shouldBe` expected
--jl