github.com/matrixorigin/matrixone@v0.7.0/pkg/sql/colexec/agg/aggUt/stddevpop_test.go (about) 1 // Copyright 2021 Matrix Origin 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package aggut 16 17 import ( 18 "testing" 19 20 "github.com/matrixorigin/matrixone/pkg/sql/colexec/agg" 21 22 "github.com/matrixorigin/matrixone/pkg/container/types" 23 ) 24 25 func TestStddevpop(t *testing.T) { 26 int8Typ := types.New(types.T_int8, 0, 0, 0) 27 decimal64Typ := types.New(types.T_decimal64, 0, 0, 0) 28 decimal128Typ := types.New(types.T_decimal128, 0, 0, 0) 29 30 testCases := []testCase{ 31 // int8 StdDevPop test 32 { 33 op: agg.AggregateStdDevPop, 34 isDistinct: false, 35 inputTyp: int8Typ, 36 37 input: []int8{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, 38 inputNsp: nil, 39 expected: []float64{2.8722813232690143}, 40 41 mergeInput: []int8{10, 11, 12, 13, 14, 15, 16, 17, 18, 19}, 42 mergeNsp: nil, 43 mergeExpect: []float64{5.766281297335398}, 44 45 testMarshal: true, 46 }, 47 // int8 StdDevPop test 48 { 49 op: agg.AggregateStdDevPop, 50 isDistinct: true, 51 inputTyp: int8Typ, 52 53 input: []int8{1, 1, 2, 2, 3, 3, 4, 4, 5, 5}, 54 inputNsp: nil, 55 expected: []float64{1.4142135623730951}, 56 57 mergeInput: []int8{6, 6, 7, 7, 8, 8, 9, 9, 10, 10}, 58 mergeNsp: nil, 59 mergeExpect: []float64{2.8722813232690143}, 60 61 testMarshal: false, 62 }, 63 // decimal64 StdDevPop test 64 { 65 op: agg.AggregateStdDevPop, 66 isDistinct: false, 67 inputTyp: decimal64Typ, 68 69 input: []int64{9, 8, 7, 6, 5, 4, 3, 2, 1, 0}, 70 inputNsp: nil, 71 expected: []float64{2.8722813232690143}, 72 73 mergeInput: []int64{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, 74 mergeNsp: nil, 75 mergeExpect: []float64{2.8722813232690143}, 76 77 testMarshal: true, 78 }, 79 { 80 op: agg.AggregateStdDevPop, 81 isDistinct: true, 82 inputTyp: decimal64Typ, 83 84 input: []int64{9, 8, 7, 6, 5, 4, 3, 2, 1, 0}, 85 inputNsp: nil, 86 expected: []float64{2.8722813232690143}, 87 88 mergeInput: []int64{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, 89 mergeNsp: nil, 90 mergeExpect: []float64{2.8722813232690143}, 91 92 testMarshal: false, 93 }, 94 // decimal128 StdDevPop test 95 { 96 op: agg.AggregateStdDevPop, 97 isDistinct: false, 98 inputTyp: decimal128Typ, 99 100 input: []int64{9, 8, 7, 6, 5, 4, 3, 2, 1, 0}, 101 inputNsp: nil, 102 expected: []float64{2.8722813232690143}, 103 104 mergeInput: []int64{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, 105 mergeNsp: nil, 106 mergeExpect: []float64{2.8722813232690143}, 107 108 testMarshal: true, 109 }, 110 { 111 op: agg.AggregateStdDevPop, 112 isDistinct: true, 113 inputTyp: decimal128Typ, 114 115 input: []int64{9, 8, 7, 6, 5, 4, 3, 2, 1, 0}, 116 inputNsp: nil, 117 expected: []float64{2.8722813232690143}, 118 119 mergeInput: []int64{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, 120 mergeNsp: nil, 121 mergeExpect: []float64{2.8722813232690143}, 122 123 testMarshal: false, 124 }, 125 } 126 127 RunTest(t, testCases) 128 }