github.com/matrixorigin/matrixone@v0.7.0/pkg/sql/plan/function/operator/is_true_false_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 operator
    16  
    17  import (
    18  	"fmt"
    19  	"testing"
    20  
    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/stretchr/testify/require"
    25  )
    26  
    27  func TestIsTrueFalse(t *testing.T) {
    28  	procs := testutil.NewProc()
    29  
    30  	testVecs := [][]*vector.Vector{
    31  		{testutil.MakeScalarNull(types.T_any, 0)},
    32  		{testutil.MakeScalarBool(false, 0)},
    33  		{testutil.MakeBooleanlVector([]bool{false, false, true, true}, []uint64{1, 3})},
    34  	}
    35  
    36  	isTrueExpect := []*vector.Vector{
    37  		testutil.MakeScalarBool(false, 1),
    38  		testutil.MakeScalarBool(false, 1),
    39  		testutil.MakeBooleanlVector([]bool{false, false, true, false}, []uint64{}),
    40  	}
    41  
    42  	isNotTrueExpect := []*vector.Vector{
    43  		testutil.MakeScalarBool(true, 1),
    44  		testutil.MakeScalarBool(true, 1),
    45  		testutil.MakeBooleanlVector([]bool{true, true, false, true}, []uint64{}),
    46  	}
    47  
    48  	isFalseExpect := []*vector.Vector{
    49  		testutil.MakeScalarBool(false, 1),
    50  		testutil.MakeScalarBool(true, 1),
    51  		testutil.MakeBooleanlVector([]bool{true, false, false, false}, []uint64{}),
    52  	}
    53  
    54  	isNotFalseExpect := []*vector.Vector{
    55  		testutil.MakeScalarBool(true, 1),
    56  		testutil.MakeScalarBool(false, 1),
    57  		testutil.MakeBooleanlVector([]bool{false, true, true, true}, []uint64{}),
    58  	}
    59  
    60  	for i := 0; i < len(testVecs); i++ {
    61  		result, err := IsTrue(testVecs[i], procs)
    62  		if err != nil {
    63  			t.Fatal(err)
    64  		}
    65  		require.True(t, testutil.CompareVectors(isTrueExpect[i], result), fmt.Sprintf("got IsTrue vector[%d] is different with expected", i))
    66  
    67  		result, err = IsNotTrue(testVecs[i], procs)
    68  		if err != nil {
    69  			t.Fatal(err)
    70  		}
    71  		require.True(t, testutil.CompareVectors(isNotTrueExpect[i], result), fmt.Sprintf("got IsNotTrue vector[%d] is different with expected", i))
    72  
    73  		result, err = IsFalse(testVecs[i], procs)
    74  		if err != nil {
    75  			t.Fatal(err)
    76  		}
    77  		require.True(t, testutil.CompareVectors(isFalseExpect[i], result), fmt.Sprintf("got IsFalse vector[%d] is different with expected", i))
    78  
    79  		result, err = IsNotFalse(testVecs[i], procs)
    80  		if err != nil {
    81  			t.Fatal(err)
    82  		}
    83  		require.True(t, testutil.CompareVectors(isNotFalseExpect[i], result), fmt.Sprintf("got IsNotFalse vector[%d] is different with expected", i))
    84  	}
    85  }