{- hamming Copyright (C) Jonathan Lamothe 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 . -} 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 numActRows = length actRes numExpRows = length expRes context "number of rows" $ it ("should be " ++ show numExpRows) $ numActRows `shouldBe` numExpRows mapM_ ( \(row, actRow, expRow) -> let numActCols = length actRow numExpCols = length expRow in context ("row " ++ show row) $ do context "number of columns" $ it ("should be " ++ show numExpCols) $ numActCols `shouldBe` numExpCols mapM_ ( \(col, actBit, expBit) -> context ("column " ++ show col) $ 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 = [ [ ( hammingAttr, ' ' ) , ( marginAttr, '0' ) , ( marginAttr, '1' ) , ( marginAttr, '2' ) , ( marginAttr, '3' ) ] , [ ( marginAttr, '0' ) , ( zeroAttr, '0' ) , ( checkAttr, '0' ) , ( checkAttr, '0' ) , ( bodyAttr, '0' ) ] , [ ( marginAttr, '1' ) , ( checkAttr, '0' ) , ( bodyAttr, '0' ) , ( bodyAttr, '0' ) , ( bodyAttr, '0' ) ] , [ ( marginAttr, '2' ) , ( checkAttr, '0' ) , ( bodyAttr, '0' ) , ( bodyAttr, '0' ) , ( bodyAttr, '0' ) ] , [ ( marginAttr, '3' ) , ( bodyAttr, '0' ) , ( bodyAttr, '0' ) , ( bodyAttr, '0' ) , ( bodyAttr, '0' ) ] ] allOne = [ [ ( hammingAttr, ' ' ) , ( marginAttr, '0' ) , ( marginAttr, '1' ) , ( marginAttr, '2' ) , ( marginAttr, '3' ) ] , [ ( marginAttr, '0' ) , ( zeroAttr, '1' ) , ( checkAttr, '1' ) , ( checkAttr , '1' ) , ( bodyAttr, '1' ) ] , [ ( marginAttr, '1' ) , ( checkAttr, '1' ) , ( bodyAttr, '1' ) , ( bodyAttr, '1' ) , ( bodyAttr, '1' ) ] , [ ( marginAttr, '2' ) , ( checkAttr, '1' ) , ( bodyAttr, '1' ) , ( bodyAttr, '1' ) , ( bodyAttr, '1' ) ] , [ ( marginAttr, '3' ) , ( bodyAttr, '1' ) , ( bodyAttr, '1' ) , ( bodyAttr, '1' ) , ( bodyAttr, '1' ) ] ] arbitrary = [ [ ( hammingAttr, ' ' ) , ( marginAttr, '0' ) , ( marginAttr, '1' ) , ( marginAttr, '2' ) , ( marginAttr, '3' ) ] , [ ( marginAttr, '0' ) , ( zeroAttr, '0' ) , ( checkAttr, '1' ) , ( checkAttr, '0' ) , ( bodyAttr, '1' ) ] , [ ( marginAttr, '1' ) , ( checkAttr, '1' ) , ( bodyAttr, '0' ) , ( bodyAttr, '1' ) , ( bodyAttr, '0' ) ] , [ ( marginAttr, '2' ) , ( checkAttr, '0' ) , ( bodyAttr, '0' ) , ( bodyAttr, '1' ) , ( bodyAttr, '1' ) ] , [ ( marginAttr, '3' ) , ( bodyAttr, '1' ) , ( bodyAttr, '1' ) , ( bodyAttr, '0' ) , ( bodyAttr, '0' ) ] ] --jl