// cmpMorphism is the set of nodes that passes comparison iterator with the same parameters.
func cmpMorphism(op iterator.Operator, node quad.Value) morphism {
	return morphism{
		Name:     "cmp",
		Reversal: func(ctx *pathContext) (morphism, *pathContext) { return cmpMorphism(op, node), ctx },
		Apply: func(qs graph.QuadStore, in graph.Iterator, ctx *pathContext) (graph.Iterator, *pathContext) {
			return iterator.NewComparison(in, op, node, qs), ctx
		},
	}
}
Beispiel #2
0
func TestCompareTypedValues(t testing.TB, gen DatabaseFunc, conf *Config) {
	qs, opts, closer := gen(t)
	defer closer()

	w := MakeWriter(t, qs, opts)

	t1 := tzero
	t2 := t1.Add(time.Hour)
	t3 := t2.Add(time.Hour * 48)
	t4 := t1.Add(time.Hour * 24 * 365)

	err := w.AddQuadSet([]quad.Quad{
		{quad.BNode("alice"), quad.BNode("bob"), quad.BNode("charlie"), quad.BNode("dani")},
		{quad.IRI("alice"), quad.IRI("bob"), quad.IRI("charlie"), quad.IRI("dani")},
		{quad.String("alice"), quad.String("bob"), quad.String("charlie"), quad.String("dani")},
		{quad.Int(100), quad.Int(112), quad.Int(110), quad.Int(20)},
		{quad.Time(t1), quad.Time(t2), quad.Time(t3), quad.Time(t4)},
	})
	require.Nil(t, err)

	for _, c := range casesCompare {
		it := iterator.NewComparison(qs.NodesAllIterator(), c.op, c.val, qs)
		ExpectIteratedValues(t, qs, it, c.expect)
	}

	for _, c := range casesCompare {
		it := iterator.NewComparison(qs.NodesAllIterator(), c.op, c.val, qs)
		nit, ok := qs.OptimizeIterator(it)
		require.Equal(t, conf.OptimizesComparison, ok)
		if conf.OptimizesComparison {
			require.NotEqual(t, it, nit)
		} else {
			require.Equal(t, it, nit)
		}
		ExpectIteratedValues(t, qs, nit, c.expect)
	}
}