github.com/matrixorigin/matrixone@v1.2.0/pkg/vm/engine/tae/compute/compare_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/matrixorigin/matrixone/pkg/container/types"
    21  	"github.com/matrixorigin/matrixone/pkg/pb/timestamp"
    22  	"github.com/matrixorigin/matrixone/pkg/vm/engine/tae/testutils"
    23  	"github.com/stretchr/testify/assert"
    24  )
    25  
    26  func TestCompareGeneric(t *testing.T) {
    27  	defer testutils.AfterTest(t)()
    28  	x := types.Decimal256{
    29  		B0_63: 0, B64_127: 0,
    30  		B128_191: 0, B192_255: 0,
    31  	}
    32  	y := types.Decimal256{
    33  		B0_63: ^x.B0_63, B64_127: ^x.B64_127,
    34  		B128_191: ^x.B128_191, B192_255: ^x.B192_255,
    35  	}
    36  	assert.True(t, CompareGeneric(x, y, types.T_decimal256) == 1)
    37  
    38  	t1 := types.TimestampToTS(timestamp.Timestamp{
    39  		PhysicalTime: 100,
    40  		LogicalTime:  10,
    41  	})
    42  	t2 := t1.Next()
    43  	assert.True(t, CompareGeneric(t1, t2, types.T_TS) == -1)
    44  
    45  	{
    46  		// Array Float32
    47  		a1 := types.ArrayToBytes[float32]([]float32{1, 2, 3})
    48  		b1 := types.ArrayToBytes[float32]([]float32{1, 2, 3})
    49  		assert.True(t, CompareGeneric(a1, b1, types.T_array_float32) == 0)
    50  
    51  		// Array Float64
    52  		a1 = types.ArrayToBytes[float64]([]float64{1, 2, 3})
    53  		b1 = types.ArrayToBytes[float64]([]float64{1, 2, 3})
    54  		assert.True(t, CompareGeneric(a1, b1, types.T_array_float64) == 0)
    55  	}
    56  
    57  }