implemented resetAbacus and rungList

This commit is contained in:
Jonathan Lamothe 2024-08-21 18:35:03 -04:00
parent eed428e7ba
commit 4ebb0bf393
2 changed files with 27 additions and 0 deletions

View File

@ -34,6 +34,8 @@ module Abacus (
getRung,
setRung,
rungL,
resetAbacus,
rungList,
) where
import Data.List (find)
@ -105,4 +107,13 @@ rungL n = lens
(fromJust . getRung n)
(flip $ setRung n)
-- | Resets all the beads on an 'Abacus'
resetAbacus :: Abacus -> Abacus
resetAbacus a = a
{ abacusRungs = map (const 0) (abacusRungs a) }
-- | Returns values on each rung as a list
rungList :: Abacus -> [Int]
rungList = abacusRungs
--jl

View File

@ -42,6 +42,8 @@ spec = describe "Abacus" $ do
getRungSpec
setRungSpec
rungLSpec
resetAbacusSpec
rungListSpec
newAbacusSpec :: Spec
newAbacusSpec = describe "newAbacusSpec" $ mapM_
@ -142,4 +144,18 @@ rungLSpec = describe "rungL" $ do
, ( "invalid rung", -1, mkA [2, 3, 5] )
]
resetAbacusSpec :: Spec
resetAbacusSpec = describe "resetAbacus" $ let
expected = Abacus 10 [0, 0, 0]
in it ("should be " ++ show expected) $ let
actual = resetAbacus $ Abacus 10 [2, 3, 5]
in expected `shouldBe` actual
rungListSpec :: Spec
rungListSpec = describe "rungList" $ let
expected = [2, 3, 5]
in it ("should be " ++ show expected) $ let
actual = rungList $ Abacus 10 [2, 3, 5]
in expected `shouldBe` actual
--jl