MCPcopy Index your code
hub / github.com/dgraph-io/dgraph / TestProcessUnary

Function TestProcessUnary

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

Source from the content-addressed store, hash-verified

691}
692
693func TestProcessUnary(t *testing.T) {
694 float3 := *new(big.Float).SetPrec(200)
695 float3.SetFloat64(3.1)
696 sqrt3 := *new(big.Float).SetPrec(200)
697 sqrt3.Sqrt(&float3)
698
699 tests := []struct {
700 in *mathTree
701 out types.Val
702 }{
703 {in: &mathTree{
704 Fn: "u-",
705 Child: []*mathTree{
706 {Const: types.Val{Tid: types.IntID, Value: int64(2)}},
707 }},
708 out: types.Val{Tid: types.IntID, Value: int64(-2.0)},
709 },
710 {in: &mathTree{
711 Fn: "u-",
712 Child: []*mathTree{
713 {Const: types.Val{Tid: types.BigFloatID, Value: float3}},
714 }},
715 out: types.Val{Tid: types.BigFloatID, Value: *big.NewFloat(-3.1).SetPrec(200)},
716 },
717 {in: &mathTree{
718 Fn: "ln",
719 Child: []*mathTree{
720 {Const: types.Val{Tid: types.IntID, Value: int64(15)}},
721 }},
722 out: types.Val{Tid: types.FloatID, Value: 2.70805020110221},
723 },
724 {in: &mathTree{
725 Fn: "exp",
726 Child: []*mathTree{
727 {Const: types.Val{Tid: types.IntID, Value: int64(1)}},
728 }},
729 out: types.Val{Tid: types.FloatID, Value: 2.718281828459045},
730 },
731 {in: &mathTree{
732 Fn: "sqrt",
733 Child: []*mathTree{
734 {Const: types.Val{Tid: types.FloatID, Value: 9.0}},
735 }},
736 out: types.Val{Tid: types.FloatID, Value: 3.0},
737 },
738 {in: &mathTree{
739 Fn: "sqrt",
740 Child: []*mathTree{
741 {Const: types.Val{Tid: types.BigFloatID, Value: float3}},
742 }},
743 out: types.Val{Tid: types.BigFloatID, Value: sqrt3},
744 },
745 {in: &mathTree{
746 Fn: "floor",
747 Child: []*mathTree{
748 {Const: types.Val{Tid: types.FloatID, Value: 2.5}},
749 }},
750 out: types.Val{Tid: types.FloatID, Value: 2.0},

Callers

nothing calls this directly

Calls 2

processUnaryFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected