implemented resetAbacus
and rungList
This commit is contained in:
parent
eed428e7ba
commit
4ebb0bf393
|
@ -34,6 +34,8 @@ module Abacus (
|
||||||
getRung,
|
getRung,
|
||||||
setRung,
|
setRung,
|
||||||
rungL,
|
rungL,
|
||||||
|
resetAbacus,
|
||||||
|
rungList,
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Data.List (find)
|
import Data.List (find)
|
||||||
|
@ -105,4 +107,13 @@ rungL n = lens
|
||||||
(fromJust . getRung n)
|
(fromJust . getRung n)
|
||||||
(flip $ setRung 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
|
--jl
|
||||||
|
|
|
@ -42,6 +42,8 @@ spec = describe "Abacus" $ do
|
||||||
getRungSpec
|
getRungSpec
|
||||||
setRungSpec
|
setRungSpec
|
||||||
rungLSpec
|
rungLSpec
|
||||||
|
resetAbacusSpec
|
||||||
|
rungListSpec
|
||||||
|
|
||||||
newAbacusSpec :: Spec
|
newAbacusSpec :: Spec
|
||||||
newAbacusSpec = describe "newAbacusSpec" $ mapM_
|
newAbacusSpec = describe "newAbacusSpec" $ mapM_
|
||||||
|
@ -142,4 +144,18 @@ rungLSpec = describe "rungL" $ do
|
||||||
, ( "invalid rung", -1, mkA [2, 3, 5] )
|
, ( "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
|
--jl
|
||||||
|
|
Loading…
Reference in New Issue
Block a user