MCPcopy Create free account
hub / github.com/dgraph-io/dgraph / TestProcessTernary

Function TestProcessTernary

query/math_test.go:971–1012  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

969}
970
971func TestProcessTernary(t *testing.T) {
972 tests := []struct {
973 in *mathTree
974 out types.Val
975 }{
976 {in: &mathTree{
977 Fn: "cond",
978 Child: []*mathTree{
979 {Val: createShardedMap(0, types.Val{Tid: types.BoolID, Value: true})},
980 {Const: types.Val{Tid: types.IntID, Value: int64(1)}},
981 {Const: types.Val{Tid: types.IntID, Value: int64(2)}},
982 }},
983 out: types.Val{Tid: types.IntID, Value: int64(1)},
984 },
985 {in: &mathTree{
986 Fn: "cond",
987 Child: []*mathTree{
988 {Val: createShardedMap(0, types.Val{Tid: types.BoolID, Value: false})},
989 {Const: types.Val{Tid: types.FloatID, Value: 1.0}},
990 {Const: types.Val{Tid: types.FloatID, Value: 2.0}},
991 }},
992 out: types.Val{Tid: types.FloatID, Value: 2.0},
993 },
994 {in: &mathTree{
995 Fn: "cond",
996 Child: []*mathTree{
997 {Val: createShardedMap(0, types.Val{Tid: types.BoolID, Value: false})},
998 {Const: types.Val{Tid: types.BigFloatID, Value: *big.NewFloat(1.456)}},
999 {Const: types.Val{Tid: types.BigFloatID, Value: *big.NewFloat(2.123)}},
1000 }},
1001 out: types.Val{Tid: types.BigFloatID, Value: *big.NewFloat(2.123)},
1002 },
1003 }
1004 for _, tc := range tests {
1005 t.Logf("Test: %s", tc.in.Fn)
1006 err := processTernary(tc.in)
1007 require.NoError(t, err)
1008 val, ok := tc.in.Val.Get(0)
1009 require.Equal(t, true, ok)
1010 require.EqualValues(t, tc.out, val)
1011 }
1012}

Callers

nothing calls this directly

Calls 3

createShardedMapFunction · 0.85
processTernaryFunction · 0.85
GetMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…