find and correct single bit errors in 16-bit hamming codes
This commit is contained in:
@@ -21,6 +21,7 @@ License along with this program. If not, see
|
||||
|
||||
module Hamming.Word16Spec (spec) where
|
||||
|
||||
import Data.Bits (shiftL, xor)
|
||||
import Data.Word (Word16)
|
||||
|
||||
import Hamming
|
||||
@@ -61,8 +62,21 @@ isValidSpec = describe "isValid" $ mapM_
|
||||
]
|
||||
|
||||
correctErrorsSpec :: Spec
|
||||
correctErrorsSpec = describe "correctErrors" $
|
||||
return ()
|
||||
correctErrorsSpec = describe "correctErrors" $ mapM_
|
||||
( \(desc, code, expected) -> context desc $ let
|
||||
actual = correctErrors code
|
||||
in it ("should be " ++ show expected) $
|
||||
actual `shouldBe` expected
|
||||
) $ ("valid", withChkBits, Just withChkBits) :
|
||||
singleBitErrors
|
||||
|
||||
singleBitErrors :: [(String, Word16, Maybe Word16)]
|
||||
singleBitErrors = map
|
||||
( \bit -> let
|
||||
mask = 1 `shiftL` bit
|
||||
code = withChkBits `xor` mask
|
||||
in ("bad bit " ++ show bit, code, Just withChkBits)
|
||||
) [0..15]
|
||||
|
||||
noChkBits :: Word16
|
||||
noChkBits = 0x34c0
|
||||
|
||||
Reference in New Issue
Block a user