Noting regions in the code

This commit is contained in:
Logan McGrath 2021-10-07 06:56:19 -07:00
parent 543ab9e7c3
commit 73a9c01e0b
2 changed files with 32 additions and 0 deletions

View File

@ -14,6 +14,10 @@ hanoi pegLabelA pegLabelB pegLabelC numDiscs =
in -- Cheat the return for now, assume that movesMade is present for TDD
Right [fromJust movesMade]
{------------------------------------------------------------------------------}
{- MOVE -----------------------------------------------------------------------}
{------------------------------------------------------------------------------}
-- | Make a move
-- Given some pegs, make a move if a move is possible and return the pegs with
-- the move that was made.
@ -56,6 +60,10 @@ move pegs =
pegs
)
{------------------------------------------------------------------------------}
{- PEGS -----------------------------------------------------------------------}
{------------------------------------------------------------------------------}
-- A set of pegs ordered from start to finish.
data Pegs = Pegs {pegsPegA :: Peg, pegsPegB :: Peg, pegsPegC :: Peg} deriving (Eq, Show)
@ -68,6 +76,10 @@ initPegs pegLabelA pegLabelB pegLabelC numDiscs =
pegsPegC = emptyPeg pegLabelC
}
{------------------------------------------------------------------------------}
{- PEG ------------------------------------------------------------------------}
{------------------------------------------------------------------------------}
-- A peg is labeled and contains a stack of discs
data Peg = Peg {pegLabel :: String, pegDiscs :: [Disc]} deriving (Eq, Show)
@ -83,6 +95,10 @@ fillPeg label numDiscs =
emptyPeg :: String -> Peg
emptyPeg label = Peg {pegLabel = label, pegDiscs = []}
{------------------------------------------------------------------------------}
{- DISC -----------------------------------------------------------------------}
{------------------------------------------------------------------------------}
-- A Disc has a size.
data Disc = Disc {discSize :: Int} deriving (Eq, Ord, Show)
@ -90,5 +106,9 @@ data Disc = Disc {discSize :: Int} deriving (Eq, Ord, Show)
stackDiscs :: Int -> [Disc]
stackDiscs numDiscs = Disc <$> reverse [1 .. numDiscs]
{------------------------------------------------------------------------------}
{- MOVE -----------------------------------------------------------------------}
{------------------------------------------------------------------------------}
-- A move has the peg that the disc was moved from and the peg it was moved to
data Move = Move {moveFrom :: String, moveTo :: String} deriving (Eq, Show)

View File

@ -38,6 +38,10 @@ spec = describe "Hanoi" $ do
Move "a" "c" -- a@[] b@[] c@[3, 2, 1]
]
{----------------------------------------------------------------------------}
{- MOVE ---------------------------------------------------------------------}
{----------------------------------------------------------------------------}
-- Testing individual moves
describe "move" $ do
it "moves the smallest peg from peg A to peg C if peg C's disc is bigger" $ do
@ -59,6 +63,10 @@ spec = describe "Hanoi" $ do
pegsPegC = (pegsPegC pegs) {pegDiscs = [Disc 2, Disc 1]}
}
{----------------------------------------------------------------------------}
{- PEGS ---------------------------------------------------------------------}
{----------------------------------------------------------------------------}
-- Testing constructor for a set of pegs
describe "initPegs" $ do
it "creates pegs with labels and fills the first peg with discs" $ do
@ -69,6 +77,10 @@ spec = describe "Hanoi" $ do
pegsPegC = Peg {pegLabel = "c", pegDiscs = []}
}
{----------------------------------------------------------------------------}
{- PEG ----------------------------------------------------------------------}
{----------------------------------------------------------------------------}
-- Testing constructor for a peg with discs
describe "fillPeg" $ do
it "creates a list of disks from biggest to smallest" $ do