Skip to content

Commit

Permalink
rename value to resultOf
Browse files Browse the repository at this point in the history
  • Loading branch information
owestphal committed Dec 18, 2023
1 parent 7b990e5 commit 9115323
Show file tree
Hide file tree
Showing 15 changed files with 32 additions and 32 deletions.
10 changes: 5 additions & 5 deletions examples/BasicExamplesSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ spec1 =
readInput x ints AssumeValid <>
readInput y nats AssumeValid <>
branch (currentValue x .>. as @Integer (currentValue y))
(writeOutput [wildcard <> value (currentValue x .+. currentValue y) <> wildcard , value (currentValue x .-. currentValue y) <> wildcard] )
(writeOutput [wildcard <> text "Result: " <> value (currentValue x .*. currentValue y)] )
(writeOutput [wildcard <> resultOf (currentValue x .+. currentValue y) <> wildcard , resultOf (currentValue x .-. currentValue y) <> wildcard] )
(writeOutput [wildcard <> text "Result: " <> resultOf (currentValue x .*. currentValue y)] )
where
x = intVar "x"
y = intVar "y"
Expand All @@ -36,7 +36,7 @@ spec2 =
readInput n nats AssumeValid <>
whileNot (sum' (allValues x) .>. currentValue n)
(readInput x ints AssumeValid) <>
writeOutput [value $ length' $ as @[Integer] $ allValues x]
writeOutput [resultOf $ length' $ as @[Integer] $ allValues x]
where
n = intVar "n"
x = intVar "x"
Expand All @@ -58,8 +58,8 @@ spec3 :: Specification
spec3 =
readInput n nats UntilValid <>
whileNot (length' (as @[Integer] $ allValues x) .==. currentValue n)
(writeOptionalOutput [value $ currentValue n .-. length' (as @[Integer] $ allValues x)] <> readInput x ints AssumeValid) <>
writeOutput [value $ sum' $ allValues x]
(writeOptionalOutput [resultOf $ currentValue n .-. length' (as @[Integer] $ allValues x)] <> readInput x ints AssumeValid) <>
writeOutput [resultOf $ sum' $ allValues x]
where
n = intVar "n"
x = intVar "x"
Expand Down
2 changes: 1 addition & 1 deletion examples/EchoSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Data.Functor ((<&>))
echoSpec :: Specification
echoSpec =
readInput x str AssumeValid <>
writeOutput [value $ as @String $ currentValue x]
writeOutput [resultOf $ as @String $ currentValue x]
where
x = stringVar "x"

Expand Down
2 changes: 1 addition & 1 deletion examples/HiddenOverflowSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Test.IOTasks
import Data.Functor ((<&>))

hiddenOverflowS :: Specification
hiddenOverflowS = writeOutput [value $ liftOpaque2 ((^),"(^)") (intLit 2) (intLit 64) .>. intLit 0 ]
hiddenOverflowS = writeOutput [resultOf $ liftOpaque2 ((^),"(^)") (intLit 2) (intLit 64) .>. intLit 0 ]

hiddenOverflowP :: MonadTeletype io => io ()
hiddenOverflowP = print $ 2^64 > 0

Check warning on line 15 in examples/HiddenOverflowSpec.hs

View workflow job for this annotation

GitHub Actions / build

• Defaulting the following constraints to type ‘Integer’

Check warning on line 15 in examples/HiddenOverflowSpec.hs

View workflow job for this annotation

GitHub Actions / build

• Defaulting the following constraints to type ‘Integer’

Check warning on line 15 in examples/HiddenOverflowSpec.hs

View workflow job for this annotation

GitHub Actions / build

• Defaulting the following constraints to type ‘Integer’

Check warning on line 15 in examples/HiddenOverflowSpec.hs

View workflow job for this annotation

GitHub Actions / build

• Defaulting the following constraints to type ‘Integer’
Expand Down
2 changes: 1 addition & 1 deletion examples/ModesSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ specification =
readInput x nats ElseAbort <>
readInput y nats AssumeValid <>
readInput z nats UntilValid <>
writeOutput [value $ sum' $ allValues [x,y,z] ]
writeOutput [resultOf $ sum' $ allValues [x,y,z] ]
where
x = intVar "x"
y = intVar "y"
Expand Down
4 changes: 2 additions & 2 deletions examples/OverflowSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ overflowSpec :: Specification
overflowSpec =
readInput n nats UntilValid <>
whileNot (length' (as @[Integer] $ allValues x) .==. currentValue n)
(writeOptionalOutput [value $ currentValue n .-. length' (as @[Integer] $ allValues x)] <> readInput x ints AssumeValid) <>
writeOutput [value $ product' $ allValues x]
(writeOptionalOutput [resultOf $ currentValue n .-. length' (as @[Integer] $ allValues x)] <> readInput x ints AssumeValid) <>
writeOutput [resultOf $ product' $ allValues x]
where
n = intVar "n"
x = intVar "x"
Expand Down
4 changes: 2 additions & 2 deletions examples/ReverseSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ reverseSpec :: Specification
reverseSpec =
readInput x str AssumeValid <>
branch (length' (as @String $ currentValue x) .>. intLit 5)
(writeOutput [value $ reverse' . as @String $ currentValue x])
(writeOutput [value $ as @String $ currentValue x])
(writeOutput [resultOf $ reverse' . as @String $ currentValue x])
(writeOutput [resultOf $ as @String $ currentValue x])
where
x = stringVar "x"

Expand Down
2 changes: 1 addition & 1 deletion examples/SumToZeroSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ sumToZeroSpec =
exit
nop
) <>
writeOutput [value $ length' $ as @[Integer] $ allValues x]
writeOutput [resultOf $ length' $ as @[Integer] $ allValues x]
where x = intVar "x"

sumToZeroProg :: MonadTeletype m => m ()
Expand Down
2 changes: 1 addition & 1 deletion examples/SymbolicPlusSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ addSpec :: Specification
addSpec =
readInput x nats AssumeValid <>
readInput y nats AssumeValid <>
writeOutput [value $ currentValue x .+. currentValue y]
writeOutput [resultOf $ currentValue x .+. currentValue y]
where
x = intVar "x"
y = intVar "y"
Expand Down
2 changes: 1 addition & 1 deletion examples/VariableMerging1Spec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ specification =
readInput y ints AssumeValid)
)
) <>
writeOutput [wildcard <> value (length' $ filter' predicate $ allValues [x,y]) <> wildcard]
writeOutput [wildcard <> resultOf (length' $ filter' predicate $ allValues [x,y]) <> wildcard]
where
predicate x = x > 0 && x `mod` 3 == 0
x = intVar "x"
Expand Down
6 changes: 3 additions & 3 deletions examples/VariableMerging2Spec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ specification =
(readInput z ints AssumeValid)
(readInput y ints AssumeValid)
<>
writeOutput [value $ as @Integer $ currentValue [x,z]] <>
writeOutput [value $ length' $ as @[Integer] $ allValues [x,y,z]] <>
writeOutput [value $ length' $ as @[Integer] $ allValues [x,y,a,z]]
writeOutput [resultOf $ as @Integer $ currentValue [x,z]] <>
writeOutput [resultOf $ length' $ as @[Integer] $ allValues [x,y,z]] <>
writeOutput [resultOf $ length' $ as @[Integer] $ allValues [x,y,a,z]]
where
x = intVar "x"
y = intVar "y"
Expand Down
2 changes: 1 addition & 1 deletion src/Test/IOTasks.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module Test.IOTasks (
isEmpty,
ints, nats, str,
OutputPattern,
wildcard, text, value,
wildcard, text, resultOf,
Varname, Var, var, intVar, stringVar,
pPrintSpecification,
-- * Terms
Expand Down
20 changes: 10 additions & 10 deletions src/Test/IOTasks/Internal/OutputPattern.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
module Test.IOTasks.Internal.OutputPattern (
PatternKind (..),
OutputPattern(..),
wildcard, text, value,
wildcard, text, resultOf,
valueTerms,
showPattern, showPatternSimple,
evalPattern,
Expand Down Expand Up @@ -35,7 +35,7 @@ data OutputPattern (k :: PatternKind) where
Wildcard :: OutputPattern k
Text :: String -> OutputPattern k
Sequence :: OutputPattern k -> OutputPattern k -> OutputPattern k
Value :: forall (tk :: TermKind) a. (Typeable a, Show a) => Term tk a -> OutputPattern 'SpecificationP
ResultOf :: forall (tk :: TermKind) a. (Typeable a, Show a) => Term tk a -> OutputPattern 'SpecificationP

data PatternKind = SpecificationP | TraceP

Expand All @@ -45,8 +45,8 @@ wildcard = Wildcard
text :: String -> OutputPattern k
text = Text

value :: (Typeable a, Show a) => Term tk a -> OutputPattern 'SpecificationP
value = Value
resultOf :: (Typeable a, Show a) => Term tk a -> OutputPattern 'SpecificationP
resultOf = ResultOf

instance Eq (OutputPattern k) where
x == y = compare x y == EQ
Expand All @@ -63,12 +63,12 @@ instance Ord (OutputPattern k) where
case compare x1 y1 of
EQ -> compare x2 y2
r -> r
compare (Value (t :: Term k1 a)) (Value (u :: Term k2 b)) =
compare (ResultOf (t :: Term k1 a)) (ResultOf (u :: Term k2 b)) =
case eqT @a @b of
Just Refl -> compareK t u
Nothing -> compare (typeRep (Proxy @a)) (typeRep (Proxy @b))
compare Value{} _ = GT
compare _ Value{} = LT
compare ResultOf{} _ = GT
compare _ ResultOf{} = LT

deriving instance Show (OutputPattern k)

Expand All @@ -88,13 +88,13 @@ valueTerms :: OutputPattern k -> [SomeTermK]
valueTerms Wildcard = []
valueTerms Text{} = []
valueTerms (Sequence x y) = valueTerms x ++ valueTerms y
valueTerms (Value t) = [SomeTermK $ SomeTerm t]
valueTerms (ResultOf t) = [SomeTermK $ SomeTerm t]

evalPattern :: ValueMap -> OutputPattern k -> (OverflowWarning, OutputPattern 'TraceP)
evalPattern _ Wildcard = (NoOverflow, Wildcard)
evalPattern _ (Text s) = (NoOverflow, Text s)
evalPattern e (Sequence x y) = evalPattern e x <> evalPattern e y
evalPattern e (Value t) = second (Text . showAsValue) $ oEval e t
evalPattern e (ResultOf t) = second (Text . showAsValue) $ oEval e t

type AddLinebreaks = Bool

Expand All @@ -113,7 +113,7 @@ showPattern :: OutputPattern k -> String
showPattern Wildcard = "_"
showPattern (Text s) = foldr showLitChar "" s
showPattern (Sequence x y) = showPattern x ++ showPattern y
showPattern (Value t) = show t
showPattern (ResultOf t) = show t

showPatternSimple :: OutputPattern k -> String
showPatternSimple p =
Expand Down
2 changes: 1 addition & 1 deletion src/Test/IOTasks/Internal/SpecificationGenerator.hs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ _optionalOutputOneof = outputOneof' True
outputOneof' :: (Typeable a, Show a) => Bool -> Gen (Term k a) -> Gen Specification
outputOneof' b ts = do
t <- ts
pure $ (if b then writeOptionalOutput else writeOutput) [Value t]
pure $ (if b then writeOptionalOutput else writeOutput) [resultOf t]

-- branch free sequence of inputs and outputs
_linearSpec :: (Typeable a, Read a, Show a) => [(Var a,ValueSet a,InputMode)] -> [(Var a,ValueSet a,InputMode)] -> Gen (Specification, [SomeVar])
Expand Down
2 changes: 1 addition & 1 deletion src/Test/IOTasks/OutputPattern.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Test.IOTasks.OutputPattern (
PatternKind (..),
OutputPattern,
wildcard, text, value,
wildcard, text, resultOf,
valueTerms,
showPattern, showPatternSimple,
evalPattern,
Expand Down
2 changes: 1 addition & 1 deletion src/Test/IOTasks/Random.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module Test.IOTasks.Random (
isEmpty,
ints, nats, str,
OutputPattern,
wildcard, text, value,
wildcard, text, resultOf,
Varname, Var, var, intVar, stringVar,
pPrintSpecification,
-- * Terms
Expand Down

0 comments on commit 9115323

Please sign in to comment.