github.com/matrixorigin/matrixone@v0.7.0/pkg/compare/compare_test.go (about)

     1  // Copyright 2021 - 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 compare
    16  
    17  import (
    18  	"testing"
    19  
    20  	"github.com/matrixorigin/matrixone/pkg/common/mpool"
    21  	"github.com/matrixorigin/matrixone/pkg/container/types"
    22  	"github.com/matrixorigin/matrixone/pkg/container/vector"
    23  	"github.com/matrixorigin/matrixone/pkg/testutil"
    24  	"github.com/matrixorigin/matrixone/pkg/vm/process"
    25  	"github.com/stretchr/testify/require"
    26  )
    27  
    28  const (
    29  	Rows = 100
    30  )
    31  
    32  type testCase struct {
    33  	desc bool
    34  	proc *process.Process
    35  	vecs []*vector.Vector
    36  }
    37  
    38  var (
    39  	tcs []testCase
    40  )
    41  
    42  func init() {
    43  	mp := mpool.MustNewZero()
    44  	tcs = []testCase{
    45  		newTestCase(true, mp, types.New(types.T_bool, 0, 0, 0)),
    46  		newTestCase(false, mp, types.New(types.T_bool, 0, 0, 0)),
    47  
    48  		newTestCase(true, mp, types.New(types.T_int8, 0, 0, 0)),
    49  		newTestCase(false, mp, types.New(types.T_int8, 0, 0, 0)),
    50  		newTestCase(true, mp, types.New(types.T_int16, 0, 0, 0)),
    51  		newTestCase(false, mp, types.New(types.T_int16, 0, 0, 0)),
    52  		newTestCase(true, mp, types.New(types.T_int32, 0, 0, 0)),
    53  		newTestCase(false, mp, types.New(types.T_int32, 0, 0, 0)),
    54  		newTestCase(true, mp, types.New(types.T_int64, 0, 0, 0)),
    55  		newTestCase(false, mp, types.New(types.T_int64, 0, 0, 0)),
    56  
    57  		newTestCase(true, mp, types.New(types.T_uint8, 0, 0, 0)),
    58  		newTestCase(false, mp, types.New(types.T_uint8, 0, 0, 0)),
    59  		newTestCase(true, mp, types.New(types.T_uint16, 0, 0, 0)),
    60  		newTestCase(false, mp, types.New(types.T_uint16, 0, 0, 0)),
    61  		newTestCase(true, mp, types.New(types.T_uint32, 0, 0, 0)),
    62  		newTestCase(false, mp, types.New(types.T_uint32, 0, 0, 0)),
    63  		newTestCase(true, mp, types.New(types.T_uint64, 0, 0, 0)),
    64  		newTestCase(false, mp, types.New(types.T_uint64, 0, 0, 0)),
    65  
    66  		newTestCase(true, mp, types.New(types.T_float32, 0, 0, 0)),
    67  		newTestCase(false, mp, types.New(types.T_float32, 0, 0, 0)),
    68  
    69  		newTestCase(true, mp, types.New(types.T_float64, 0, 0, 0)),
    70  		newTestCase(false, mp, types.New(types.T_float64, 0, 0, 0)),
    71  
    72  		newTestCase(true, mp, types.New(types.T_date, 0, 0, 0)),
    73  		newTestCase(false, mp, types.New(types.T_date, 0, 0, 0)),
    74  
    75  		newTestCase(true, mp, types.New(types.T_time, 0, 0, 0)),
    76  		newTestCase(false, mp, types.New(types.T_time, 0, 0, 0)),
    77  
    78  		newTestCase(true, mp, types.New(types.T_datetime, 0, 0, 0)),
    79  		newTestCase(false, mp, types.New(types.T_datetime, 0, 0, 0)),
    80  
    81  		newTestCase(true, mp, types.New(types.T_timestamp, 0, 0, 0)),
    82  		newTestCase(false, mp, types.New(types.T_timestamp, 0, 0, 0)),
    83  
    84  		newTestCase(true, mp, types.New(types.T_decimal64, 0, 0, 0)),
    85  		newTestCase(false, mp, types.New(types.T_decimal64, 0, 0, 0)),
    86  
    87  		newTestCase(true, mp, types.New(types.T_decimal128, 0, 0, 0)),
    88  		newTestCase(false, mp, types.New(types.T_decimal128, 0, 0, 0)),
    89  
    90  		newTestCase(true, mp, types.New(types.T_varchar, types.MaxVarcharLen, 0, 0)),
    91  		newTestCase(false, mp, types.New(types.T_varchar, types.MaxVarcharLen, 0, 0)),
    92  
    93  		newTestCase(true, mp, types.New(types.T_blob, 0, 0, 0)),
    94  		newTestCase(false, mp, types.New(types.T_blob, 0, 0, 0)),
    95  
    96  		newTestCase(true, mp, types.New(types.T_text, 0, 0, 0)),
    97  		newTestCase(false, mp, types.New(types.T_text, 0, 0, 0)),
    98  	}
    99  }
   100  
   101  func TestCompare(t *testing.T) {
   102  	for _, tc := range tcs {
   103  		nb0 := tc.proc.Mp().CurrNB()
   104  		c := New(tc.vecs[0].Typ, tc.desc, false)
   105  		c.Set(0, tc.vecs[0])
   106  		c.Set(1, tc.vecs[1])
   107  		err := c.Copy(0, 1, 0, 0, tc.proc)
   108  		require.NoError(t, err)
   109  		c.Compare(0, 1, 0, 0)
   110  		nb1 := tc.proc.Mp().CurrNB()
   111  		require.Equal(t, nb0, nb1)
   112  		// XXX MPOOL
   113  		// tv.vecs[0].Free modifies tc.proc.Mp()
   114  		tc.vecs[0].Free(tc.proc.Mp())
   115  		tc.vecs[1].Free(tc.proc.Mp())
   116  	}
   117  }
   118  
   119  func newTestCase(desc bool, m *mpool.MPool, typ types.Type) testCase {
   120  	vecs := make([]*vector.Vector, 2)
   121  	vecs[0] = testutil.NewVector(Rows, typ, m, true, nil)
   122  	vecs[1] = testutil.NewVector(Rows, typ, m, true, nil)
   123  	return testCase{
   124  		desc: desc,
   125  		vecs: vecs,
   126  		proc: testutil.NewProcessWithMPool(m),
   127  	}
   128  }