ginger/gg/gg_test.go
Brian Picciano 1e30ad6959 Strip out most of the functionality of gg.Graph
`gg.Graph` has been reworked in its internal functionality, to more
closely match the capability of a purely stack-based implementation. The
current implementation is _very_ inefficient, however. Tests have been
deliberately left pretty sparse, as I expect the internals to continue
to change significantly.
2021-12-27 10:11:07 -07:00

94 lines
2.1 KiB
Go

package gg
import (
"strconv"
"testing"
"github.com/stretchr/testify/assert"
)
func TestEqual(t *testing.T) {
i := func(i int64) Value {
return Value{Number: &i}
}
n := func(n string) Value {
return Value{Name: &n}
}
tests := []struct {
a, b *Graph
exp bool
}{
{
a: ZeroGraph,
b: ZeroGraph,
exp: true,
},
{
a: ZeroGraph,
b: ZeroGraph.AddValueIn(ValueOut(n("in"), n("incr")), n("out")),
exp: false,
},
{
a: ZeroGraph.AddValueIn(ValueOut(n("in"), n("incr")), n("out")),
b: ZeroGraph.AddValueIn(ValueOut(n("in"), n("incr")), n("out")),
exp: true,
},
{
a: ZeroGraph.AddValueIn(ValueOut(n("in"), n("incr")), n("out")),
b: ZeroGraph.AddValueIn(TupleOut([]OpenEdge{
ValueOut(n("in"), n("ident")),
ValueOut(i(1), n("ident")),
}, n("add")), n("out")),
exp: false,
},
{
// tuples are different order
a: ZeroGraph.AddValueIn(TupleOut([]OpenEdge{
ValueOut(i(1), n("ident")),
ValueOut(n("in"), n("ident")),
}, n("add")), n("out")),
b: ZeroGraph.AddValueIn(TupleOut([]OpenEdge{
ValueOut(n("in"), n("ident")),
ValueOut(i(1), n("ident")),
}, n("add")), n("out")),
exp: false,
},
{
a: ZeroGraph.
AddValueIn(ValueOut(n("in"), n("incr")), n("out")).
AddValueIn(ValueOut(n("in2"), n("incr2")), n("out2")),
b: ZeroGraph.
AddValueIn(ValueOut(n("in"), n("incr")), n("out")),
exp: false,
},
{
a: ZeroGraph.
AddValueIn(ValueOut(n("in"), n("incr")), n("out")).
AddValueIn(ValueOut(n("in2"), n("incr2")), n("out2")),
b: ZeroGraph.
AddValueIn(ValueOut(n("in"), n("incr")), n("out")).
AddValueIn(ValueOut(n("in2"), n("incr2")), n("out2")),
exp: true,
},
{
// order of value ins shouldn't matter
a: ZeroGraph.
AddValueIn(ValueOut(n("in"), n("incr")), n("out")).
AddValueIn(ValueOut(n("in2"), n("incr2")), n("out2")),
b: ZeroGraph.
AddValueIn(ValueOut(n("in2"), n("incr2")), n("out2")).
AddValueIn(ValueOut(n("in"), n("incr")), n("out")),
exp: true,
},
}
for i, test := range tests {
t.Run(strconv.Itoa(i), func(t *testing.T) {
assert.Equal(t, test.exp, Equal(test.a, test.b))
})
}
}