From 633a1b7b2455d5e314fe6d4ee64fb9d3eddd675e Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Wed, 31 Jul 2024 18:22:12 -0400 Subject: [PATCH] fixed hamming code attribute names --- src/Hamming/App/Widgets.hs | 1 + src/Hamming/App/Widgets/Internal.hs | 30 +++-- test/Hamming/App/Widgets/InternalSpec.hs | 150 +++++++++++------------ 3 files changed, 93 insertions(+), 88 deletions(-) diff --git a/src/Hamming/App/Widgets.hs b/src/Hamming/App/Widgets.hs index 48d63d7..8666291 100644 --- a/src/Hamming/App/Widgets.hs +++ b/src/Hamming/App/Widgets.hs @@ -30,6 +30,7 @@ module Hamming.App.Widgets ( -- ** Attribute Names hammingAttr, marginAttr, + bodyAttr, checkAttr, zeroAttr, ) where diff --git a/src/Hamming/App/Widgets/Internal.hs b/src/Hamming/App/Widgets/Internal.hs index 8da7f50..98e3753 100644 --- a/src/Hamming/App/Widgets/Internal.hs +++ b/src/Hamming/App/Widgets/Internal.hs @@ -35,6 +35,7 @@ module Hamming.App.Widgets.Internal ( -- ** Attribute Names hammingAttr, marginAttr, + bodyAttr, checkAttr, zeroAttr, ) where @@ -48,7 +49,7 @@ import Hamming.App.Types hammingW' :: AppState -> [[(AttrName, Char)]] hammingW' state = let - header = (mempty, ' ') : map (marginAttr,) ['0'..'3'] + header = (hammingAttr, ' ') : map (marginAttr,) ['0'..'3'] body = hammingBody state in header : zipWith (\n row -> (marginAttr, n) : row) @@ -61,8 +62,11 @@ hammingAttr = attrName "hamming" marginAttr :: AttrName marginAttr = hammingAttr <> attrName "margin" +bodyAttr :: AttrName +bodyAttr = hammingAttr <> attrName "body" + checkAttr :: AttrName -checkAttr = hammingAttr <> attrName "check" +checkAttr = bodyAttr <> attrName "check" zeroAttr :: AttrName zeroAttr = checkAttr <> attrName "zero" @@ -82,22 +86,22 @@ hammingBody state = let [ [ ( zeroAttr, 0x0001 ) , ( checkAttr, 0x0002 ) , ( checkAttr, 0x0004 ) - , ( mempty, 0x0008 ) + , ( bodyAttr, 0x0008 ) ] , [ ( checkAttr, 0x0010 ) - , ( mempty, 0x0020 ) - , ( mempty, 0x0040 ) - , ( mempty, 0x0080 ) + , ( bodyAttr, 0x0020 ) + , ( bodyAttr, 0x0040 ) + , ( bodyAttr, 0x0080 ) ] , [ ( checkAttr, 0x0100 ) - , ( mempty, 0x0200 ) - , ( mempty, 0x0400 ) - , ( mempty, 0x0800 ) + , ( bodyAttr, 0x0200 ) + , ( bodyAttr, 0x0400 ) + , ( bodyAttr, 0x0800 ) ] - , [ ( mempty, 0x1000 ) - , ( mempty, 0x2000 ) - , ( mempty, 0x4000 ) - , ( mempty, 0x8000 ) + , [ ( bodyAttr, 0x1000 ) + , ( bodyAttr, 0x2000 ) + , ( bodyAttr, 0x4000 ) + , ( bodyAttr, 0x8000 ) ] ] diff --git a/test/Hamming/App/Widgets/InternalSpec.hs b/test/Hamming/App/Widgets/InternalSpec.hs index fa893dc..815c0d8 100644 --- a/test/Hamming/App/Widgets/InternalSpec.hs +++ b/test/Hamming/App/Widgets/InternalSpec.hs @@ -65,99 +65,99 @@ hammingW'Spec = describe "hammingW'" $ mapM_ ] where mkState c = initialState & hammingCode .~ c allZero = - [ [ ( mempty, ' ' ) - , ( marginAttr, '0' ) - , ( marginAttr, '1' ) - , ( marginAttr, '2' ) - , ( marginAttr, '3' ) + [ [ ( hammingAttr, ' ' ) + , ( marginAttr, '0' ) + , ( marginAttr, '1' ) + , ( marginAttr, '2' ) + , ( marginAttr, '3' ) ] - , [ ( marginAttr, '0' ) - , ( zeroAttr, '0' ) - , ( checkAttr, '0' ) - , ( checkAttr, '0' ) - , ( mempty, '0' ) + , [ ( marginAttr, '0' ) + , ( zeroAttr, '0' ) + , ( checkAttr, '0' ) + , ( checkAttr, '0' ) + , ( bodyAttr, '0' ) ] - , [ ( marginAttr, '1' ) - , ( checkAttr, '0' ) - , ( mempty, '0' ) - , ( mempty, '0' ) - , ( mempty, '0' ) + , [ ( marginAttr, '1' ) + , ( checkAttr, '0' ) + , ( bodyAttr, '0' ) + , ( bodyAttr, '0' ) + , ( bodyAttr, '0' ) ] - , [ ( marginAttr, '2' ) - , ( checkAttr, '0' ) - , ( mempty, '0' ) - , ( mempty, '0' ) - , ( mempty, '0' ) + , [ ( marginAttr, '2' ) + , ( checkAttr, '0' ) + , ( bodyAttr, '0' ) + , ( bodyAttr, '0' ) + , ( bodyAttr, '0' ) ] - , [ ( marginAttr, '3' ) - , ( mempty, '0' ) - , ( mempty, '0' ) - , ( mempty, '0' ) - , ( mempty, '0' ) + , [ ( marginAttr, '3' ) + , ( bodyAttr, '0' ) + , ( bodyAttr, '0' ) + , ( bodyAttr, '0' ) + , ( bodyAttr, '0' ) ] ] allOne = - [ [ ( mempty, ' ' ) - , ( marginAttr, '0' ) - , ( marginAttr, '1' ) - , ( marginAttr, '2' ) - , ( marginAttr, '3' ) + [ [ ( hammingAttr, ' ' ) + , ( marginAttr, '0' ) + , ( marginAttr, '1' ) + , ( marginAttr, '2' ) + , ( marginAttr, '3' ) ] - , [ ( marginAttr, '0' ) - , ( zeroAttr, '1' ) - , ( checkAttr, '1' ) - , ( checkAttr, '1' ) - , ( mempty, '1' ) + , [ ( marginAttr, '0' ) + , ( zeroAttr, '1' ) + , ( checkAttr, '1' ) + , ( checkAttr , '1' ) + , ( bodyAttr, '1' ) ] - , [ ( marginAttr, '1' ) - , ( checkAttr, '1' ) - , ( mempty, '1' ) - , ( mempty, '1' ) - , ( mempty, '1' ) + , [ ( marginAttr, '1' ) + , ( checkAttr, '1' ) + , ( bodyAttr, '1' ) + , ( bodyAttr, '1' ) + , ( bodyAttr, '1' ) ] - , [ ( marginAttr, '2' ) - , ( checkAttr, '1' ) - , ( mempty, '1' ) - , ( mempty, '1' ) - , ( mempty, '1' ) + , [ ( marginAttr, '2' ) + , ( checkAttr, '1' ) + , ( bodyAttr, '1' ) + , ( bodyAttr, '1' ) + , ( bodyAttr, '1' ) ] - , [ ( marginAttr, '3' ) - , ( mempty, '1' ) - , ( mempty, '1' ) - , ( mempty, '1' ) - , ( mempty, '1' ) + , [ ( marginAttr, '3' ) + , ( bodyAttr, '1' ) + , ( bodyAttr, '1' ) + , ( bodyAttr, '1' ) + , ( bodyAttr, '1' ) ] ] arbitrary = - [ [ ( mempty, ' ' ) - , ( marginAttr, '0' ) - , ( marginAttr, '1' ) - , ( marginAttr, '2' ) - , ( marginAttr, '3' ) + [ [ ( hammingAttr, ' ' ) + , ( marginAttr, '0' ) + , ( marginAttr, '1' ) + , ( marginAttr, '2' ) + , ( marginAttr, '3' ) ] - , [ ( marginAttr, '0' ) - , ( zeroAttr, '0' ) - , ( checkAttr, '1' ) - , ( checkAttr, '0' ) - , ( mempty, '1' ) + , [ ( marginAttr, '0' ) + , ( zeroAttr, '0' ) + , ( checkAttr, '1' ) + , ( checkAttr, '0' ) + , ( bodyAttr, '1' ) ] - , [ ( marginAttr, '1' ) - , ( checkAttr, '1' ) - , ( mempty, '0' ) - , ( mempty, '1' ) - , ( mempty, '0' ) + , [ ( marginAttr, '1' ) + , ( checkAttr, '1' ) + , ( bodyAttr, '0' ) + , ( bodyAttr, '1' ) + , ( bodyAttr, '0' ) ] - , [ ( marginAttr, '2' ) - , ( checkAttr, '0' ) - , ( mempty, '0' ) - , ( mempty, '1' ) - , ( mempty, '1' ) + , [ ( marginAttr, '2' ) + , ( checkAttr, '0' ) + , ( bodyAttr, '0' ) + , ( bodyAttr, '1' ) + , ( bodyAttr, '1' ) ] - , [ ( marginAttr, '3' ) - , ( mempty, '1' ) - , ( mempty, '1' ) - , ( mempty, '0' ) - , ( mempty, '0' ) + , [ ( marginAttr, '3' ) + , ( bodyAttr, '1' ) + , ( bodyAttr, '1' ) + , ( bodyAttr, '0' ) + , ( bodyAttr, '0' ) ] ]