diff --git a/src/Abacus.hs b/src/Abacus.hs index ca56072..49e22e1 100644 --- a/src/Abacus.hs +++ b/src/Abacus.hs @@ -24,7 +24,7 @@ License along with this program. If not, see -} -module Abacus (Abacus, newAbacus, getNumBeads) where +module Abacus (Abacus, newAbacus, getNumBeads, getNumRungs) where import Abacus.Internal @@ -40,8 +40,12 @@ newAbacus beads rungs = if beads < 1 || rungs < 1 then Nothing else Just $ Abacus beads $ replicate rungs 0 --- | Returns the number of beads per rung in an abacus +-- | Returns the number of beads per rung in an "Abacus" getNumBeads :: Abacus -> Int getNumBeads = abacusNumBeads +-- | Returns the number of rungs in an "Abacus" +getNumRungs :: Abacus -> Int +getNumRungs = length . abacusRungs + --jl diff --git a/src/Abacus/Internal.hs b/src/Abacus/Internal.hs index 75f45ed..5af9a67 100644 --- a/src/Abacus/Internal.hs +++ b/src/Abacus/Internal.hs @@ -36,7 +36,7 @@ module Abacus.Internal (Abacus (..)) where data Abacus = Abacus { abacusNumBeads :: Int -- ^ The number of beads per rung of the abacus - , abacusRows :: [Int] + , abacusRungs :: [Int] -- ^ The number of beads slid across each rung } deriving (Eq, Show) diff --git a/test/AbacusSpec.hs b/test/AbacusSpec.hs index 8a4c6ff..1975c47 100644 --- a/test/AbacusSpec.hs +++ b/test/AbacusSpec.hs @@ -31,6 +31,7 @@ spec :: Spec spec = describe "Abacus" $ do newAbacusSpec getNumBeadsSpec + getNumRungsSpec newAbacusSpec :: Spec newAbacusSpec = describe "newAbacusSpec" $ mapM_ @@ -58,4 +59,18 @@ getNumBeadsSpec = describe "getNumBeads" $ mapM_ tenBeads = build 10 build n = fromJust $ newAbacus n 10 +getNumRungsSpec :: Spec +getNumRungsSpec = describe "getNumRungs" $ mapM_ + ( \(desc, input, expected) -> context desc $ let + actual = getNumRungs input + in it ("should be " ++ show expected) $ + actual `shouldBe` expected + ) + [ ( "one rung", oneRung, 1 ) + , ( "ten rungs", tenRungs, 10 ) + ] where + oneRung = build 1 + tenRungs = build 10 + build n = fromJust $ newAbacus 10 n + --jl