Noting regions in the code
This commit is contained in:
parent
543ab9e7c3
commit
73a9c01e0b
@ -14,6 +14,10 @@ hanoi pegLabelA pegLabelB pegLabelC numDiscs =
|
|||||||
in -- Cheat the return for now, assume that movesMade is present for TDD
|
in -- Cheat the return for now, assume that movesMade is present for TDD
|
||||||
Right [fromJust movesMade]
|
Right [fromJust movesMade]
|
||||||
|
|
||||||
|
{------------------------------------------------------------------------------}
|
||||||
|
{- MOVE -----------------------------------------------------------------------}
|
||||||
|
{------------------------------------------------------------------------------}
|
||||||
|
|
||||||
-- | Make a move
|
-- | Make a move
|
||||||
-- Given some pegs, make a move if a move is possible and return the pegs with
|
-- Given some pegs, make a move if a move is possible and return the pegs with
|
||||||
-- the move that was made.
|
-- the move that was made.
|
||||||
@ -56,6 +60,10 @@ move pegs =
|
|||||||
pegs
|
pegs
|
||||||
)
|
)
|
||||||
|
|
||||||
|
{------------------------------------------------------------------------------}
|
||||||
|
{- PEGS -----------------------------------------------------------------------}
|
||||||
|
{------------------------------------------------------------------------------}
|
||||||
|
|
||||||
-- A set of pegs ordered from start to finish.
|
-- A set of pegs ordered from start to finish.
|
||||||
data Pegs = Pegs {pegsPegA :: Peg, pegsPegB :: Peg, pegsPegC :: Peg} deriving (Eq, Show)
|
data Pegs = Pegs {pegsPegA :: Peg, pegsPegB :: Peg, pegsPegC :: Peg} deriving (Eq, Show)
|
||||||
|
|
||||||
@ -68,6 +76,10 @@ initPegs pegLabelA pegLabelB pegLabelC numDiscs =
|
|||||||
pegsPegC = emptyPeg pegLabelC
|
pegsPegC = emptyPeg pegLabelC
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{------------------------------------------------------------------------------}
|
||||||
|
{- PEG ------------------------------------------------------------------------}
|
||||||
|
{------------------------------------------------------------------------------}
|
||||||
|
|
||||||
-- A peg is labeled and contains a stack of discs
|
-- A peg is labeled and contains a stack of discs
|
||||||
data Peg = Peg {pegLabel :: String, pegDiscs :: [Disc]} deriving (Eq, Show)
|
data Peg = Peg {pegLabel :: String, pegDiscs :: [Disc]} deriving (Eq, Show)
|
||||||
|
|
||||||
@ -83,6 +95,10 @@ fillPeg label numDiscs =
|
|||||||
emptyPeg :: String -> Peg
|
emptyPeg :: String -> Peg
|
||||||
emptyPeg label = Peg {pegLabel = label, pegDiscs = []}
|
emptyPeg label = Peg {pegLabel = label, pegDiscs = []}
|
||||||
|
|
||||||
|
{------------------------------------------------------------------------------}
|
||||||
|
{- DISC -----------------------------------------------------------------------}
|
||||||
|
{------------------------------------------------------------------------------}
|
||||||
|
|
||||||
-- A Disc has a size.
|
-- A Disc has a size.
|
||||||
data Disc = Disc {discSize :: Int} deriving (Eq, Ord, Show)
|
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 :: Int -> [Disc]
|
||||||
stackDiscs numDiscs = Disc <$> reverse [1 .. numDiscs]
|
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
|
-- 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)
|
data Move = Move {moveFrom :: String, moveTo :: String} deriving (Eq, Show)
|
||||||
|
@ -38,6 +38,10 @@ spec = describe "Hanoi" $ do
|
|||||||
Move "a" "c" -- a@[] b@[] c@[3, 2, 1]
|
Move "a" "c" -- a@[] b@[] c@[3, 2, 1]
|
||||||
]
|
]
|
||||||
|
|
||||||
|
{----------------------------------------------------------------------------}
|
||||||
|
{- MOVE ---------------------------------------------------------------------}
|
||||||
|
{----------------------------------------------------------------------------}
|
||||||
|
|
||||||
-- Testing individual moves
|
-- Testing individual moves
|
||||||
describe "move" $ do
|
describe "move" $ do
|
||||||
it "moves the smallest peg from peg A to peg C if peg C's disc is bigger" $ 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]}
|
pegsPegC = (pegsPegC pegs) {pegDiscs = [Disc 2, Disc 1]}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{----------------------------------------------------------------------------}
|
||||||
|
{- PEGS ---------------------------------------------------------------------}
|
||||||
|
{----------------------------------------------------------------------------}
|
||||||
|
|
||||||
-- Testing constructor for a set of pegs
|
-- Testing constructor for a set of pegs
|
||||||
describe "initPegs" $ do
|
describe "initPegs" $ do
|
||||||
it "creates pegs with labels and fills the first peg with discs" $ 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 = []}
|
pegsPegC = Peg {pegLabel = "c", pegDiscs = []}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{----------------------------------------------------------------------------}
|
||||||
|
{- PEG ----------------------------------------------------------------------}
|
||||||
|
{----------------------------------------------------------------------------}
|
||||||
|
|
||||||
-- Testing constructor for a peg with discs
|
-- Testing constructor for a peg with discs
|
||||||
describe "fillPeg" $ do
|
describe "fillPeg" $ do
|
||||||
it "creates a list of disks from biggest to smallest" $ do
|
it "creates a list of disks from biggest to smallest" $ do
|
||||||
|
Loading…
Reference in New Issue
Block a user