github.com/whtcorpsinc/MilevaDB-Prod@v0.0.0-20211104133533-f57f4be3b597/interlock/aggfuncs/func_avg_test.go (about) 1 // Copyright 2020 WHTCORPS INC, Inc. 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 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package aggfuncs_test 15 16 import ( 17 "testing" 18 19 . "github.com/whtcorpsinc/check" 20 "github.com/whtcorpsinc/BerolinaSQL/ast" 21 "github.com/whtcorpsinc/BerolinaSQL/allegrosql" 22 "github.com/whtcorpsinc/milevadb/interlock/aggfuncs" 23 ) 24 25 func (s *testSuite) TestMergePartialResult4Avg(c *C) { 26 tests := []aggTest{ 27 builPosetDaggTester(ast.AggFuncAvg, allegrosql.TypeNewDecimal, 5, 2.0, 3.0, 2.375), 28 builPosetDaggTester(ast.AggFuncAvg, allegrosql.TypeDouble, 5, 2.0, 3.0, 2.375), 29 } 30 for _, test := range tests { 31 s.testMergePartialResult(c, test) 32 } 33 } 34 35 func (s *testSuite) TestAvg(c *C) { 36 tests := []aggTest{ 37 builPosetDaggTester(ast.AggFuncAvg, allegrosql.TypeNewDecimal, 5, nil, 2.0), 38 builPosetDaggTester(ast.AggFuncAvg, allegrosql.TypeDouble, 5, nil, 2.0), 39 } 40 for _, test := range tests { 41 s.testAggFunc(c, test) 42 } 43 } 44 45 func (s *testSuite) TestMemAvg(c *C) { 46 tests := []aggMemTest{ 47 builPosetDaggMemTester(ast.AggFuncAvg, allegrosql.TypeNewDecimal, 5, 48 aggfuncs.DefPartialResult4AvgDecimalSize, defaultUFIDelateMemDeltaGens, false), 49 builPosetDaggMemTester(ast.AggFuncAvg, allegrosql.TypeNewDecimal, 5, 50 aggfuncs.DefPartialResult4AvgDistinctDecimalSize, distinctUFIDelateMemDeltaGens, true), 51 builPosetDaggMemTester(ast.AggFuncAvg, allegrosql.TypeDouble, 5, 52 aggfuncs.DefPartialResult4AvgFloat64Size, defaultUFIDelateMemDeltaGens, false), 53 builPosetDaggMemTester(ast.AggFuncAvg, allegrosql.TypeDouble, 5, 54 aggfuncs.DefPartialResult4AvgDistinctFloat64Size, distinctUFIDelateMemDeltaGens, true), 55 } 56 for _, test := range tests { 57 s.testAggMemFunc(c, test) 58 } 59 } 60 61 func BenchmarkAvg(b *testing.B) { 62 s := testSuite{} 63 s.SetUpSuite(nil) 64 65 rowNum := 50000 66 tests := []aggTest{ 67 builPosetDaggTester(ast.AggFuncAvg, allegrosql.TypeNewDecimal, rowNum, nil, 2.0), 68 builPosetDaggTester(ast.AggFuncAvg, allegrosql.TypeDouble, rowNum, nil, 2.0), 69 } 70 for _, test := range tests { 71 s.benchmarkAggFunc(b, test) 72 } 73 }