Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MitchStevens committed Jan 13, 2024
1 parent b794fe7 commit 4e722cf
Show file tree
Hide file tree
Showing 15 changed files with 80 additions and 60 deletions.
17 changes: 16 additions & 1 deletion src/Game/Board/EvaluableBoard.purs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,22 @@
An `EvaluatableBoard` also generates information about the states of ports which is used in rendering. Generating extra information has an overhead cost, for the evaluation of board that don't need to provide internal port information, use `CompiledBoard` for better performance.
-}

module Game.Board.EvaluableBoard where
module Game.Board.EvaluableBoard
( EvaluableBoard(..)
, EvaluableM
, buildEvaluableBoard
, evalWithPortInfo
, evalWithPortInfoAt
, evaluableBoardPiece
, extractOutputs
, getInputOnEdge
, getOuterPort
, injectInputs
, runEvaluableM
, toEvaluableBoard
, topologicalSort
)
where

import Data.Lens
import Prelude
Expand Down
4 changes: 2 additions & 2 deletions src/Game/Piece/BasicPiece.purs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Data.Newtype (class Newtype)
import Data.Traversable (class Foldable, traverse)
import Data.Tuple (Tuple(..))
import Data.Unfoldable (fromMaybe)
import Game.Capacity (Capacity(..))
import Game.Capacity (Capacity(..), clampSignal)
import Game.Direction (CardinalDirection(..))
import Game.Direction as Direction
import Game.Expression (Expression(..), evaluate, ref)
Expand All @@ -35,7 +35,7 @@ basicPiece basic = Piece
{ name: basic.name
, eval: \inputs -> flip M.mapMaybe basic.ports $ case _ of
BasicInput -> Nothing
BasicOutput expression -> Just (evaluate inputs expression)
BasicOutput expression -> Just (clampSignal basic.capacity $ evaluate inputs expression)
, complexity: basic.complexity

, shouldRipple: true
Expand Down
1 change: 0 additions & 1 deletion src/Game/Piece/TwoBitSuite.purs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import Prelude
import Data.Foldable (fold)
import Data.Map as M
import Data.Maybe (Maybe(..))
import Data.Posix.Signal (Signal)
import Data.Tuple (Tuple(..))
import Game.Capacity (Capacity(..))
import Game.Direction as Direction
Expand Down
8 changes: 4 additions & 4 deletions test/Test/Component/Board/Types.purs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module Test.Component.Board.Types where

import Game.Board
import Game.Piece
import Prelude


import Prelude

import Component.Board.Types (boardPortInfo)
Expand All @@ -13,9 +13,9 @@ import Data.Map as M
import Data.Maybe (Maybe(..))
import Data.Tuple (Tuple(..))
import Data.Zipper as Z
import Game.Board (standardBoard)
import Game.Capacity (Capacity(..))
import Game.Direction as Direction
import Game.Piece (Capacity(..), getPorts, idPiece, inputPort, outputPort)
import Game.Port (inputPort, outputPort)
import Test.Game.Board (testBoard)
import Test.Spec (Spec, describe, describeOnly, hoistSpec, it)
import Test.Spec.Assertions (shouldReturn)
Expand Down
4 changes: 3 additions & 1 deletion test/Test/Component/Rendering/Wire.purs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
module Test.Component.Rendering.Wire where

import Game.Piece
import Prelude

import Component.Rendering.Wire (wirePath)
import Data.Map as M
import Data.Tuple (Tuple(..))
import Game.Capacity (Capacity(..))
import Game.Direction as Direction
import Game.Piece (Capacity(..), inputPort, outputPort)
import Game.Port (inputPort, outputPort)
import Game.Signal (Signal(..))
import Halogen.Svg.Attributes (CommandPositionReference(..), l, m, q)
import Test.Spec (Spec, describe, it, itOnly)
Expand Down
9 changes: 4 additions & 5 deletions test/Test/Game/Board.purs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@ import Debug (trace)
import Effect.Aff (Aff, Error, error)
import Effect.Aff.Class (class MonadAff)
import Effect.Class.Console (log)
import Game.Board (Board(..), RelativeEdge, absolute, relative, standardBoard)
import Game.Board.Operation (BoardError(..), BoardT, addPiece, decreaseSize, emptyBoard, evalBoardM, execBoardM, getPieceInfo, increaseSize, removePiece, rotatePieceBy, runBoardT, validBoardSize)
import Game.Board.Path (addBoardPath)
import Game.Board.Query (adjacentRelativeEdge, connectedRelativeEdge, getBoardPort, getPortOnEdge, toAbsoluteEdge, toRelativeEdge)
import Game.Board (Board(..), RelativeEdge, absolute, addBoardPath, addPiece, adjacentRelativeEdge, execBoardM, getBoardPort, getPortOnEdge, increaseSize, relative, rotatePieceBy, standardBoard, toAbsoluteEdge, toRelativeEdge)
import Game.Capacity (Capacity(..))
import Game.Direction (CardinalDirection, allDirections)
import Game.Direction as Direction
import Game.Location (Location(..), location)
import Game.Piece (Capacity(..), andPiece, inputPort, notPiece, outputPort, xorPiece)
import Game.Piece (andPiece, notPiece, xorPiece)
import Game.Piece as Port
import Game.Port (inputPort, outputPort)
import Game.Rotation (rotation)
import Game.Signal (Signal(..))
import Halogen.HTML (object)
Expand Down
23 changes: 9 additions & 14 deletions test/Test/Game/Board/EvaluableBoard.purs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module Test.Game.Board.EvaluableBoard where

import Game.Board
import Game.Piece
import Prelude

import Control.Monad.Error.Class (class MonadError)
Expand All @@ -24,15 +26,12 @@ import Effect.Aff (Aff)
import Effect.Class (class MonadEffect)
import Effect.Class.Console (log, logShow)
import Effect.Exception (Error)
import Game.Board (Board(..), RelativeEdge, relative, relativeEdgeLocation)
import Game.Board.EvaluableBoard (EvaluableBoard(..), buildEvaluableBoard, evalWithPortInfo, evalWithPortInfoAt, evaluableBoardPiece, getOuterPort, getPort, getPorts, injectInputs, toEvaluableBoard, topologicalSort)
import Game.Board.PortInfo (PortInfo)
import Game.Board.PseudoPiece (isPseudoInput, psuedoPiece)
import Game.Board.Query (buildConnectionMap)
import Game.Capacity (Capacity(..))
import Game.Direction as Direction
import Game.Level (binaryTestInputs)
import Game.Location (location)
import Game.Piece (Capacity(..), andPiece, eval, inputPort, isOutput, notPiece, orPiece, outputPort)
import Game.Port (inputPort, isOutput, outputPort)
import Game.PortInfo (PortInfo)
import Game.Signal (Signal(..))
import Test.Game.Board (testBoard, testBoardCrossOver, toAff)
import Test.Game.Board.Operation (exceptToAff)
Expand Down Expand Up @@ -153,13 +152,8 @@ tests = do
it "eval" do
for_ (binaryTestInputs [Direction.Left, Direction.Up]) \inputs ->
eval (evaluableBoardPiece testEvaluableBoard) inputs `shouldEqual` eval orPiece inputs
it "getPort" do
getPort Direction.Up `shouldReturn` Just (inputPort OneBit)
getPort Direction.Right `shouldReturn` Just (outputPort OneBit)
getPort Direction.Down `shouldReturn` Nothing
getPort Direction.Left `shouldReturn` Just (inputPort OneBit)
it "getPorts" do
getPorts `shouldReturn` M.fromFoldable
asks (evaluableBoardPiece >>> getPorts) `shouldReturn` M.fromFoldable
[ Tuple Direction.Up (inputPort OneBit)
, Tuple Direction.Right (outputPort OneBit)
, Tuple Direction.Left (inputPort OneBit)
Expand All @@ -186,14 +180,15 @@ tests = do
, Tuple Direction.Down (location 2 5)
]

getPorts `shouldReturn` M.fromFoldable
ports <- asks (evaluableBoardPiece >>> getPorts)
ports `shouldEqual` M.fromFoldable
[ Tuple Direction.Up (inputPort OneBit)
, Tuple Direction.Right (outputPort OneBit)
, Tuple Direction.Left (inputPort OneBit)
, Tuple Direction.Down (outputPort OneBit)
]

(M.filter isOutput <$> getPorts) `shouldReturn` M.fromFoldable
(M.filter isOutput ports) `shouldEqual` M.fromFoldable
[ Tuple Direction.Right (outputPort OneBit)
, Tuple Direction.Down (outputPort OneBit)
]
Expand Down
6 changes: 1 addition & 5 deletions test/Test/Game/Board/Operation.purs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ import Effect.Aff.Class (class MonadAff, liftAff)
import Effect.Class (class MonadEffect)
import Effect.Class.Console (log)
import Effect.Exception (Error, error)
import Game.Board (Board(..), _pieces, relativeEdgeLocation, standardBoard)
import Game.Board.EvaluableBoard (topologicalSort)
import Game.Board.Operation (BoardError(..), addPiece, addPieceNoUpdate, applyBoardEvent, decreaseSize, increaseSize, removePiece, rotatePieceBy, updatePortsAround, validBoardSize)
import Game.Board.Path (addBoardPath)
import Game.Board.Query (buildConnectionMap)
import Game.Board (Board(..), _pieces, relativeEdgeLocation, standardBoard, topologicalSort, BoardError(..), addPiece, addPieceNoUpdate, applyBoardEvent, decreaseSize, increaseSize, removePiece, rotatePieceBy, updatePortsAround, validBoardSize, addBoardPath, buildConnectionMap)
import Game.Direction as Direction
import Game.GameEvent (BoardEvent(..))
import Game.Location (location)
Expand Down
7 changes: 2 additions & 5 deletions test/Test/Game/Board/Path.purs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,10 @@ import Data.Tuple (Tuple(..))
import Data.Zipper (Zipper(..))
import Data.Zipper as Z
import Debug (trace)
import Game.Board (Board(..), _pieces, standardBoard)
import Game.Board.Operation (addPiece, execBoardM, rotatePieceBy)
import Game.Board.Path (addBoardPath)
import Game.Board
import Game.Direction as Direction
import Game.GameEvent (BoardEvent(..))
import Game.Location (location)
import Game.Piece (PieceId(..), andPiece, crossPiece, getOutputDirs, idPiece, leftPiece, name, notPiece, rightPiece)
import Game.Piece
import Game.Rotation (rotation)
import Partial.Unsafe (unsafeCrashWith)
import Test.Game.Board (testBoard, toAff)
Expand Down
7 changes: 4 additions & 3 deletions test/Test/Game/Board/Query.purs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ import Data.Map as M
import Data.Maybe (Maybe(..))
import Data.Tuple (Tuple(..))
import Effect.Exception (Error)
import Game.Board (Board(..), _pieces, absolute, relative)
import Game.Board.Query (adjacentRelativeEdge, buildConnectionMap, capacityRipple, getPortOnEdge, toAbsoluteEdge, toRelativeEdge)
import Game.Board (Board(..), _pieces, absolute, relative, adjacentRelativeEdge, buildConnectionMap, capacityRipple, getPortOnEdge, toAbsoluteEdge, toRelativeEdge)
import Game.Capacity (Capacity(..))
import Game.Direction (allDirections)
import Game.Direction as Direction
import Game.Location (location)
import Game.Piece (Capacity(..), inputPort, outputPort, portCapacity, getPort)
import Game.Piece (getPort)
import Game.Port (inputPort, outputPort, portCapacity)
import Test.Game.Board (testBoard, toAff)
import Test.Game.Location (allLocations)
import Test.Spec (Spec, SpecT, before, beforeAll_, describe, describeOnly, hoistSpec, it)
Expand Down
21 changes: 5 additions & 16 deletions test/Test/Game/Piece/Port.purs → test/Test/Game/Capacity.purs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
module Test.Game.Piece.Port where
module Test.Game.Capacity where

import Prelude

import Data.Maybe (Maybe(..))
import Game.Piece (Capacity(..), clampSignal, doubleCapacity, halveCapacity, inputPort, matchingPort, outputPort, portMatches)
import Game.Capacity (Capacity(..), clampSignal, doubleCapacity, halveCapacity)
import Game.Signal (Signal(..))
import Test.QuickCheck (assertLessThan)
import Test.Spec (Spec, describe, it, itOnly)
import Test.Spec.Assertions (shouldEqual, shouldNotEqual)
import Test.Spec (Spec, describe, it)
import Test.Spec.Assertions (shouldEqual)
import Test.Spec.QuickCheck (quickCheck)

spec :: Spec Unit
Expand Down Expand Up @@ -39,15 +39,4 @@ spec = do
quickCheck \s -> clampSignal OneBit (Signal s) `assertLessThan` Signal 2
quickCheck \s -> clampSignal TwoBit (Signal s) `assertLessThan` Signal 4
quickCheck \s -> clampSignal FourBit (Signal s) `assertLessThan` Signal 16
quickCheck \s -> clampSignal EightBit (Signal s) `assertLessThan` Signal 256


describe "Port" do
describe "matchingPort" do
it "should match matching ports" do
matchingPort (inputPort OneBit) `shouldEqual` outputPort OneBit
matchingPort (inputPort FourBit) `shouldEqual` outputPort FourBit
it "should not match the same port type" do
matchingPort (inputPort OneBit) `shouldNotEqual` inputPort OneBit
it "should not match different capacities" do
matchingPort (inputPort OneBit) `shouldNotEqual` outputPort TwoBit
quickCheck \s -> clampSignal EightBit (Signal s) `assertLessThan` Signal 256
1 change: 0 additions & 1 deletion test/Test/Game/Level/Problem.purs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import Data.Tuple (Tuple(..), uncurry)
import Effect.Aff (Aff, error)
import Effect.Exception (error)
import Game.Board (Board(..), standardBoard)
import Game.Board.Operation (BoardT, addPiece, emptyBoard, evalBoardM, execBoardM, rotatePieceBy)
import Game.Direction as Direction
import Game.Level.Problem (Problem)
import Game.Piece (idPiece)
Expand Down
4 changes: 3 additions & 1 deletion test/Test/Game/Piece/BasicPiece.purs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import Data.HeytingAlgebra (ff, tt)
import Data.Map as M
import Data.Maybe (Maybe(..))
import Data.Tuple (Tuple(..))
import Game.Capacity (Capacity(..))
import Game.Direction as Direction
import Game.Piece (Capacity(..), andPiece, eval, getPorts, inputPort, notPiece, orPiece, outputPort, xorPiece)
import Game.Piece (andPiece, eval, getPorts, notPiece, orPiece, xorPiece)
import Game.Piece as Port
import Game.Port (inputPort, outputPort)
import Test.Spec (Spec, describe, it)
import Test.Spec.Assertions (shouldEqual, shouldNotEqual)

Expand Down
3 changes: 2 additions & 1 deletion test/Test/Game/Piece/FusePiece.purs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import Prelude

import Data.Foldable (for_)
import Data.Tuple (Tuple(..), uncurry)
import Game.Piece (Capacity(..), clampSignal, fuseSignals, severSignal)
import Game.Capacity (Capacity(..), clampSignal)
import Game.Piece (fuseSignals, severSignal)
import Game.Signal (Signal(..))
import Test.QuickCheck ((===))
import Test.Spec (Spec, describe, it, itOnly)
Expand Down
25 changes: 25 additions & 0 deletions test/Test/Game/Port.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module Test.Game.Port where

import Prelude

import Data.Maybe (Maybe(..))
import Game.Capacity (Capacity(..))
import Game.Port (inputPort, matchingPort, outputPort)
import Game.Signal (Signal(..))
import Test.QuickCheck (assertLessThan)
import Test.Spec (Spec, describe, it, itOnly)
import Test.Spec.Assertions (shouldEqual, shouldNotEqual)
import Test.Spec.QuickCheck (quickCheck)


spec :: Spec Unit
spec =
describe "Port" do
describe "matchingPort" do
it "should match matching ports" do
matchingPort (inputPort OneBit) `shouldEqual` outputPort OneBit
matchingPort (inputPort FourBit) `shouldEqual` outputPort FourBit
it "should not match the same port type" do
matchingPort (inputPort OneBit) `shouldNotEqual` inputPort OneBit
it "should not match different capacities" do
matchingPort (inputPort OneBit) `shouldNotEqual` outputPort TwoBit

0 comments on commit 4e722cf

Please sign in to comment.