build hamming code display widget

This commit is contained in:
2024-07-19 20:50:33 -04:00
parent e216432a77
commit ef23b67688
8 changed files with 336 additions and 4 deletions

View File

@@ -0,0 +1,225 @@
{-
hamming
Copyright (C) Jonathan Lamothe <jonathan@jlamothe.net>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public
License along with this program. If not, see
<https://www.gnu.org/licenses/>.
-}
module Hamming.App.Widgets.InternalSpec (spec) where
import Lens.Micro ((&), (.~))
import Test.Hspec (Spec, context, describe, it, shouldBe)
import Hamming.App
import Hamming.App.Types
import Hamming.App.Widgets.Internal
spec :: Spec
spec = describe "Internal"
hammingW'Spec
hammingW'Spec :: Spec
hammingW'Spec = describe "hammingW'" $ mapM_
( \(desc, state, expRes) -> context desc $ do
let actRes = hammingW' state
context "number of rows" $
it "should be 4" $
length actRes `shouldBe` 4
mapM_
( \(rowNum, actRow, expRow) ->
context ("row " ++ show rowNum) $ do
context "number of columns" $
it "should be 4" $
length actRow `shouldBe` 4
mapM_
( \(colNum, actBit, expBit) ->
context ("column " ++ show colNum) $
it ("should be " ++ show expBit) $
actBit `shouldBe` expBit
) $ zip3 [(0 :: Int)..] actRow expRow
) $ zip3 [(0 :: Int)..] actRes expRes
)
[ ( "all zero", mkState 0, allZero )
, ( "all one", mkState 0xffff, allOne )
, ( "arbitrary", mkState 0x3c5a, arbitrary )
] where
mkState c = initialState & hammingCode .~ c
allZero =
[ [ ( ["zero", "check"]
, '0'
)
, ( ["check"]
, '0'
)
, ( ["check"]
, '0'
)
, ( []
, '0'
)
]
, [ ( ["check"]
, '0'
)
, ( []
, '0'
)
, ( []
, '0'
)
, ( []
, '0'
)
]
, [ ( ["check"]
, '0'
)
, ( []
, '0'
)
, ( []
, '0'
)
, ( []
, '0'
)
]
, [ ( []
, '0'
)
, ( []
, '0'
)
, ( []
, '0'
)
, ( []
, '0'
)
]
]
allOne =
[ [ ( ["zero", "check"]
, '1'
)
, ( ["check"]
, '1'
)
, ( ["check"]
, '1'
)
, ( []
, '1'
)
]
, [ ( ["check"]
, '1'
)
, ( []
, '1'
)
, ( []
, '1'
)
, ( []
, '1'
)
]
, [ ( ["check"]
, '1'
)
, ( []
, '1'
)
, ( []
, '1'
)
, ( []
, '1'
)
]
, [ ( []
, '1'
)
, ( []
, '1'
)
, ( []
, '1'
)
, ( []
, '1'
)
]
]
arbitrary =
[ [ ( ["zero", "check"]
, '0'
)
, ( ["check"]
, '1'
)
, ( ["check"]
, '0'
)
, ( []
, '1'
)
]
, [ ( ["check"]
, '1'
)
, ( []
, '0'
)
, ( []
, '1'
)
, ( []
, '0'
)
]
, [ ( ["check"]
, '0'
)
, ( []
, '0'
)
, ( []
, '1'
)
, ( []
, '1'
)
]
, [ ( []
, '1'
)
, ( []
, '1'
)
, ( []
, '0'
)
, ( []
, '0'
)
]
]
--jl

View File

@@ -0,0 +1,32 @@
{-
hamming
Copyright (C) Jonathan Lamothe <jonathan@jlamothe.net>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public
License along with this program. If not, see
<https://www.gnu.org/licenses/>.
-}
module Hamming.App.WidgetsSpec (spec) where
import Test.Hspec (Spec, describe)
import qualified Hamming.App.Widgets.InternalSpec as Internal
spec :: Spec
spec = describe "Widgets"
Internal.spec
--jl

32
test/Hamming/AppSpec.hs Normal file
View File

@@ -0,0 +1,32 @@
{-
hamming
Copyright (C) Jonathan Lamothe <jonathan@jlamothe.net>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public
License along with this program. If not, see
<https://www.gnu.org/licenses/>.
-}
module Hamming.AppSpec (spec) where
import Test.Hspec (Spec, describe)
import qualified Hamming.App.WidgetsSpec as Widgets
spec :: Spec
spec = describe "App"
Widgets.spec
--jl

View File

@@ -23,10 +23,12 @@ module HammingSpec (spec) where
import Test.Hspec (Spec, describe)
import qualified Hamming.AppSpec as App
import qualified Hamming.Word16Spec as Word16
spec :: Spec
spec = describe "Hamming"
spec = describe "Hamming" $ do
Word16.spec
App.spec
--jl