From fe9263cfae3d8b7947c28d025edd37a4a6ed80c4 Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Wed, 21 Aug 2024 20:34:08 -0400 Subject: [PATCH] implemented rendering of beads on abacus --- src/Abacus/App/Widgets/Internal.hs | 8 ++++++- test/Abacus/App/Widgets/InternalSpec.hs | 29 ++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/Abacus/App/Widgets/Internal.hs b/src/Abacus/App/Widgets/Internal.hs index 2fe24d5..293d2be 100644 --- a/src/Abacus/App/Widgets/Internal.hs +++ b/src/Abacus/App/Widgets/Internal.hs @@ -53,7 +53,13 @@ abacusLeft s = else ' ' beads :: Abacus -> [(String, String)] -beads = undefined +beads a = map + ( \n -> + ( replicate (getNumBeads a - n) 'O' + , replicate n 'O' + ) + ) + (rungList a) abacusRight :: AppState -> [String] abacusRight = undefined diff --git a/test/Abacus/App/Widgets/InternalSpec.hs b/test/Abacus/App/Widgets/InternalSpec.hs index 6d5701d..6284b55 100644 --- a/test/Abacus/App/Widgets/InternalSpec.hs +++ b/test/Abacus/App/Widgets/InternalSpec.hs @@ -21,11 +21,12 @@ License along with this program. If not, see module Abacus.App.Widgets.InternalSpec (spec) where -import Lens.Micro.Platform ((&), (.~)) +import Lens.Micro.Platform ((^.), (&), (.~)) import Test.Hspec (Spec, describe, context, it, shouldBe) import Abacus.App.Types import Abacus.App.Widgets.Internal +import Abacus.Internal spec :: Spec spec = describe "Internal" $ do @@ -90,8 +91,30 @@ abacusLeftSpec = describe "abacusLeft" $ mapM_ negState = initialState & rungNum .~ (-1) beadsSpec :: Spec -beadsSpec = describe "beads" $ - return () +beadsSpec = describe "beads" $ mapM_ + ( \(desc, a, expected) -> context desc $ + it ("should be " ++ show expected) $ + beads a `shouldBe` expected + ) + [ ( "initial state", initAb, initRes ) + , ( "1-10", countAb, countRes ) + ] + where + initAb = initialState^.abacus + countAb = Abacus 10 [1..10] + initRes = replicate 10 ("OOOOOOOOOO", "") + countRes = + [ ( "OOOOOOOOO", "O" ) + , ( "OOOOOOOO", "OO" ) + , ( "OOOOOOO", "OOO" ) + , ( "OOOOOO", "OOOO" ) + , ( "OOOOO", "OOOOO" ) + , ( "OOOO", "OOOOOO" ) + , ( "OOO", "OOOOOOO" ) + , ( "OO", "OOOOOOOO" ) + , ( "O", "OOOOOOOOO" ) + , ( "", "OOOOOOOOOO" ) + ] abacusRightSpec :: Spec abacusRightSpec = describe "abacusRight" $