github.com/matrixorigin/matrixone@v0.7.0/pkg/vectorize/div/integer_div_test.go (about) 1 // Copyright 2022 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 div 16 17 import ( 18 "testing" 19 20 "github.com/matrixorigin/matrixone/pkg/common/moerr" 21 "github.com/matrixorigin/matrixone/pkg/testutil" 22 ) 23 24 func TestF32IntegerDivByZero(t *testing.T) { 25 as := make([]float32, 2) 26 bs := make([]float32, 2) 27 for i := 0; i < 2; i++ { 28 as[i] = 50.23 29 bs[i] = 0 30 } 31 cs := make([]int64, 2) 32 av := testutil.MakeFloat32Vector(as, nil) 33 bv := testutil.MakeFloat32Vector(bs, nil) 34 cv := testutil.MakeInt64Vector(cs, nil) 35 36 err := NumericIntegerDivFloat[float32](av, bv, cv) 37 if err != nil { 38 if !moerr.IsMoErrCode(err, moerr.ErrDivByZero) { 39 t.Fatalf("should have div by zero error.") 40 } 41 } 42 } 43 44 func TestF64IntegerDivByZero(t *testing.T) { 45 as := make([]float64, 2) 46 bs := make([]float64, 2) 47 for i := 0; i < 2; i++ { 48 as[i] = 50 49 bs[i] = float64(i) 50 } 51 cs := make([]int64, 2) 52 av := testutil.MakeFloat64Vector(as, nil) 53 bv := testutil.MakeFloat64Vector(bs, nil) 54 cv := testutil.MakeInt64Vector(cs, nil) 55 56 err := NumericIntegerDivFloat[float64](av, bv, cv) 57 if err != nil { 58 if !moerr.IsMoErrCode(err, moerr.ErrDivByZero) { 59 t.Fatalf("should have div by zero error.") 60 } 61 } 62 } 63 64 func TestF32IntegerDiv(t *testing.T) { 65 as := make([]float32, 1) 66 bs := make([]float32, 1) 67 cs := make([]int64, 1) 68 for i := 0; i < 1; i++ { 69 as[i] = float32((i + 1) * 100) 70 bs[i] = float32(5) 71 } 72 73 av := testutil.MakeFloat32Vector(as, nil) 74 bv := testutil.MakeFloat32Vector(bs, nil) 75 cv := testutil.MakeInt64Vector(cs, nil) 76 77 err := NumericIntegerDivFloat[float32](av, bv, cv) 78 if err != nil { 79 t.Fatal(err, "decimal64 integer div failed") 80 } 81 } 82 83 func TestF64IntegerDiv(t *testing.T) { 84 as := make([]float64, 10) 85 bs := make([]float64, 10) 86 cs := make([]int64, 10) 87 for i := 0; i < 10; i++ { 88 as[i] = float64(i * 1024) 89 bs[i] = float64(8.2) 90 } 91 92 av := testutil.MakeFloat64Vector(as, nil) 93 bv := testutil.MakeFloat64Vector(bs, nil) 94 cv := testutil.MakeInt64Vector(cs, nil) 95 96 err := NumericIntegerDivFloat[float64](av, bv, cv) 97 if err != nil { 98 t.Fatalf("decimal64 div failed") 99 } 100 }