From 319f682d4ae0d0b0aca11b2d1b851917de17eea3 Mon Sep 17 00:00:00 2001 From: Rowan Torbitzky-Lane Date: Sat, 1 Feb 2025 01:24:27 -0600 Subject: [PATCH] clean up/basic tests --- src/State.hs | 11 +++-------- test/Main.hs | 9 ++++++++- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/State.hs b/src/State.hs index 6cb3b08..959d3b0 100644 --- a/src/State.hs +++ b/src/State.hs @@ -23,7 +23,7 @@ data Gene | GeneVectorBool [Bool] | GeneVectorString [String] | GeneVectorChar [Char] - | StateFunc (State -> State) + | StateFunc (State -> State, String) -- The string stores the name of the function | PlaceInput String | Close | Block [Gene] @@ -42,7 +42,7 @@ instance Eq Gene where GeneVectorString xs == GeneVectorString ys = xs == ys GeneVectorChar xs == GeneVectorChar ys = xs == ys Close == Close = True - StateFunc _ == StateFunc _ = True -- This line is probably not the best thing to do + StateFunc (_, nameX) == StateFunc (_, nameY) = nameX == nameY Block x == Block y = x == y _ == _ = False @@ -52,7 +52,7 @@ instance Show Gene where show (GeneBool x) = "Bool: " <> show x show (GeneString x) = "String: " <> x show (GeneChar x) = "Char: " <> show x - show (StateFunc x) = "Func: " <> show x + show (StateFunc (_, funcName)) = "Func: " <> funcName show (PlaceInput x) = "In: " <> show x show (GeneVectorInt xs) = "Int Vec: " <> show xs show (GeneVectorFloat xs) = "Float Vec: " <> show xs @@ -101,10 +101,6 @@ data State = State } deriving (Show, Eq, Generic) --- This needs to be updated later -instance Show (State -> State) where - show _ = "unnamed" - instance Arbitrary State where arbitrary = do arbExec <- arbitrary @@ -122,7 +118,6 @@ instance Arbitrary State where arbParameter <- arbitrary -- arbInput <- arbitrary State arbExec arbCode arbInt arbFloat arbBool arbString arbChar arbVectorInt arbVectorFloat arbVectorBool arbVectorString arbVectorChar arbParameter <$> arbitrary - -- Thanks hlint lol instance CoArbitrary State diff --git a/test/Main.hs b/test/Main.hs index 2717136..cef8d76 100644 --- a/test/Main.hs +++ b/test/Main.hs @@ -16,9 +16,16 @@ myArgs = -- quickCheckWith myArgs prop_IntAdd +-- These two used for ghci testing +qcw :: Testable a => a-> IO () +qcw = quickCheckWith myArgs + +vcw :: Testable a => a-> IO () +vcw = verboseCheckWith myArgs + -- Running this with a large max size leads quickCheck to hang, and that's bad prop_IntAdd :: State -> Bool -prop_IntAdd state@(State {_int = i1 : i2 : is}) = i1 + i2 == head (_int (instructionIntAdd state)) +prop_IntAdd state@(State {_int = i1 : i2 : _}) = i1 + i2 == head (_int (instructionIntAdd state)) prop_IntAdd state = state == instructionIntAdd state main :: IO ()