A small go library to lazily calculate dependent variables.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
832 B

package lazy
import (
tools "gitlab.com/Pixdigit/goTestTools"
func TestResolving(t *testing.T) {
test := 0.0
p1 := Invariant(1)
p2 := Invariant(2)
p3 := Invariant(3)
p4 := Invariant(4)
p5 := PointerVar(&test)
test = 1
result := Div(Sub(Mul(Add(p1, p2), p3), p4), p5)
t.Log("Calculation result:", result.Value)
tools.Test(result.Value == 5, "invalid result", t)
tools.Test(result.HasDependency(p1), "No dependency detected", t)
tools.Test(result.HasDependency(p2), "No dependency detected", t)
tools.Test(result.HasDependency(p3), "No dependency detected", t)
tools.Test(result.HasDependency(p4), "No dependency detected", t)
tools.Test(result.HasDependency(p5), "No dependency detected", t)
tools.Test(!result.HasDependency(Invariant(0)), "Dependency on independed node", t)