diff --git a/src/Abacus.hs b/src/Abacus.hs index c530d00..ca56072 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) where +module Abacus (Abacus, newAbacus, getNumBeads) where import Abacus.Internal @@ -40,4 +40,8 @@ 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 +getNumBeads :: Abacus -> Int +getNumBeads = abacusNumBeads + --jl diff --git a/test/AbacusSpec.hs b/test/AbacusSpec.hs index b416b0c..8a4c6ff 100644 --- a/test/AbacusSpec.hs +++ b/test/AbacusSpec.hs @@ -21,14 +21,16 @@ License along with this program. If not, see module AbacusSpec (spec) where +import Data.Maybe (fromJust) import Test.Hspec (Spec, context, describe, it, shouldBe) import Abacus import Abacus.Internal spec :: Spec -spec = describe "Abacus" +spec = describe "Abacus" $ do newAbacusSpec + getNumBeadsSpec newAbacusSpec :: Spec newAbacusSpec = describe "newAbacusSpec" $ mapM_ @@ -42,4 +44,18 @@ newAbacusSpec = describe "newAbacusSpec" $ mapM_ , ( "no rungs", 10, 0, Nothing ) ] +getNumBeadsSpec :: Spec +getNumBeadsSpec = describe "getNumBeads" $ mapM_ + ( \(desc, input, expected) -> context desc $ let + actual = getNumBeads input + in it ("should be " ++ show expected) $ + actual `shouldBe` expected + ) + [ ( "one bead", oneBead, 1 ) + , ( "ten beads", tenBeads, 10 ) + ] where + oneBead = build 1 + tenBeads = build 10 + build n = fromJust $ newAbacus n 10 + --jl