View Source Guesswork.Answer.Test (Guesswork v0.6.0)
A Guesswork.Answer.Computation
bound to a concrete value that can be used to
verify correctness.
Summary
Functions
Checks the environment for the inputs, and then runs the stored functions before checking the result against the value. If the inputs are not present or not concrete values, an error is returned.
Types
@type t() :: %Guesswork.Answer.Test{ computation: Guesswork.Answer.Computation.t(), negated: boolean(), value: Guesswork.Ast.Term.t() }
Functions
@spec new(Guesswork.Answer.Computation.t(), Guesswork.Ast.Term.t(), boolean()) :: t()
@spec run(t(), Guesswork.Ast.Statement.env(), String.t()) :: Guesswork.Answer.Computation.error() | {:ok, boolean()}
Checks the environment for the inputs, and then runs the stored functions before checking the result against the value. If the inputs are not present or not concrete values, an error is returned.
Examples
iex> var = Guesswork.Ast.Variable.new("x")
...> comp = Guesswork.Answer.Computation.new([var], fn x -> x + 1 end)
...> test1 = Guesswork.Answer.Test.new(comp, 2, false)
...> test2 = Guesswork.Answer.Test.new(comp, 2, true)
...> Guesswork.Answer.Test.run(test1, %{var => 1}, "test")
{:ok, true}
iex> Guesswork.Answer.Test.run(test2, %{var => 1}, "test")
{:ok, false}
iex> Guesswork.Answer.Test.run(test1, %{var => 2}, "test")
{:ok, false}
iex> Guesswork.Answer.Test.run(test2, %{var => 2}, "test")
{:ok, true}