github.com/matrixorigin/matrixone@v0.7.0/pkg/vm/engine/tae/compute/compute_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 compute
    16  
    17  import (
    18  	"testing"
    19  
    20  	"github.com/stretchr/testify/require"
    21  
    22  	"github.com/RoaringBitmap/roaring"
    23  	"github.com/matrixorigin/matrixone/pkg/container/types"
    24  	"github.com/matrixorigin/matrixone/pkg/vm/engine/tae/containers"
    25  	"github.com/matrixorigin/matrixone/pkg/vm/engine/tae/testutils"
    26  	"github.com/stretchr/testify/assert"
    27  )
    28  
    29  func TestShuffleByDeletes(t *testing.T) {
    30  	defer testutils.AfterTest(t)()
    31  	origMask := roaring.New()
    32  	origVals := make(map[uint32]any)
    33  	origMask.Add(1)
    34  	origVals[1] = 1
    35  	origMask.Add(10)
    36  	origVals[10] = 10
    37  	origMask.Add(20)
    38  	origVals[20] = 20
    39  	origMask.Add(30)
    40  	origVals[30] = 30
    41  
    42  	deletes := roaring.New()
    43  	deletes.Add(0)
    44  	deletes.Add(8)
    45  	deletes.Add(22)
    46  
    47  	destDelets := ShuffleByDeletes(deletes, deletes)
    48  	t.Log(destDelets.String())
    49  }
    50  
    51  func TestCheckRowExists(t *testing.T) {
    52  	defer testutils.AfterTest(t)()
    53  	typ := types.T_int32.ToType()
    54  	vec := containers.MockVector2(typ, 100, 0)
    55  	_, exist := GetOffsetByVal(vec, int32(55), nil)
    56  	require.True(t, exist)
    57  	_, exist = GetOffsetByVal(vec, int32(0), nil)
    58  	require.True(t, exist)
    59  	_, exist = GetOffsetByVal(vec, int32(99), nil)
    60  	require.True(t, exist)
    61  
    62  	_, exist = GetOffsetByVal(vec, int32(-1), nil)
    63  	require.False(t, exist)
    64  	_, exist = GetOffsetByVal(vec, int32(100), nil)
    65  	require.False(t, exist)
    66  	_, exist = GetOffsetByVal(vec, int32(114514), nil)
    67  	require.False(t, exist)
    68  
    69  	dels := roaring.NewBitmap()
    70  	dels.Add(uint32(55))
    71  	_, exist = GetOffsetByVal(vec, int32(55), dels)
    72  	require.False(t, exist)
    73  }
    74  
    75  func TestAppendNull(t *testing.T) {
    76  	defer testutils.AfterTest(t)()
    77  	colTypes := types.MockColTypes(17)
    78  	check := func(typ types.Type) {
    79  		vec := containers.MockVector2(typ, 10, 0)
    80  		defer vec.Close()
    81  		vec.Append(types.Null{})
    82  		assert.Equal(t, 11, vec.Length())
    83  		assert.True(t, vec.IsNull(10))
    84  		t.Log(vec.String())
    85  	}
    86  	for _, typ := range colTypes {
    87  		check(typ)
    88  	}
    89  }
    90  
    91  func TestBinarySearch(t *testing.T) {
    92  	defer testutils.AfterTest(t)()
    93  	slice := []int{1, 2, 6, 9, 12}
    94  	pos := BinarySearch(slice, 3)
    95  	assert.Equal(t, -1, pos)
    96  	pos = BinarySearch(slice, 6)
    97  	assert.Equal(t, 2, pos)
    98  }