github.com/matrixorigin/matrixone@v0.7.0/pkg/sql/plan/function/builtin/unary/abs_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 unary 16 17 import ( 18 "log" 19 "testing" 20 21 "github.com/matrixorigin/matrixone/pkg/common/moerr" 22 "github.com/matrixorigin/matrixone/pkg/container/vector" 23 "github.com/matrixorigin/matrixone/pkg/testutil" 24 "github.com/smartystreets/goconvey/convey" 25 ) 26 27 func Test_AbsUint64(t *testing.T) { 28 convey.Convey("Test abs for uint64 succ", t, func() { 29 var uint64VecBase = []uint64{1, 0} 30 var nsp1 = []uint64{2} 31 var origVecs = make([]*vector.Vector, 1) 32 var proc = testutil.NewProc() 33 origVecs[0] = testutil.MakeUint64Vector(uint64VecBase, nsp1) 34 vec, err := AbsUInt64(origVecs, proc) 35 if err != nil { 36 log.Fatal(err) 37 } 38 data, ok := vec.Col.([]uint64) 39 if !ok { 40 log.Fatal(moerr.NewInternalError(proc.Ctx, "the AbsUint64 function return value type is not []uint6")) 41 } 42 compVec := []uint64{1, 0} 43 compNsp := []int64{2} 44 45 for i := 0; i < len(compVec); i++ { 46 convey.So(data[i], convey.ShouldEqual, compVec[i]) 47 } 48 j := 0 49 for i := 0; i < len(compVec); i++ { 50 if j < len(compNsp) { 51 if compNsp[j] == int64(i) { 52 convey.So(vec.Nsp.Np.Contains(uint64(i)), convey.ShouldBeTrue) 53 j++ 54 } else { 55 convey.So(vec.Nsp.Np.Contains(uint64(i)), convey.ShouldBeFalse) 56 } 57 } else { 58 convey.So(vec.Nsp.Np.Contains(uint64(i)), convey.ShouldBeFalse) 59 } 60 } 61 62 }) 63 }