implemented calculation of check bits for Word16

This commit is contained in:
2024-06-30 08:57:13 -04:00
parent ee0cbe47b2
commit af26fcedd8
5 changed files with 141 additions and 2 deletions

View File

@@ -0,0 +1,66 @@
{-
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.Word16Spec (spec) where
import Data.Word (Word16)
import Hamming
import Test.Hspec (Spec, context, describe, it, shouldBe)
spec :: Spec
spec = describe "Word16" $ do
setCheckBitsSpec
isValidSpec
correctErrorsSpec
setCheckBitsSpec :: Spec
setCheckBitsSpec = describe "setCheckBits" $ mapM_
( \(desc, code, expected) -> context desc $ let
actual = setCheckBits code
in it ("should be " ++ show expected) $
actual `shouldBe` expected
)
[ ( "all zeroes", 0, 0 )
, ( "all ones", 0xffff, 0xffff )
, ( "no check bits", noChkBits, withChkBits )
, ( "bad check bits", badChkBits, withChkBits )
]
isValidSpec :: Spec
isValidSpec = describe "isValid" $
return ()
correctErrorsSpec :: Spec
correctErrorsSpec = describe "correctErrors" $
return ()
noChkBits :: Word16
noChkBits = 0x34c0
withChkBits :: Word16
withChkBits = 0x35c5
badChkBits :: Word16
badChkBits = 0x34d2
--jl

32
test/HammingSpec.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 HammingSpec (spec) where
import Test.Hspec (Spec, describe)
import qualified Hamming.Word16Spec as Word16
spec :: Spec
spec = describe "Hamming"
Word16.spec
--jl

View File

@@ -21,7 +21,9 @@ License along with this program. If not, see
import Test.Hspec (hspec)
import qualified HammingSpec as Hamming
main :: IO ()
main = hspec $ return ()
main = hspec Hamming.spec
--jl