github.com/matrixorigin/matrixone@v0.7.0/pkg/sql/plan/function/operator/isnot_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  	"testing"
    19  
    20  	"github.com/matrixorigin/matrixone/pkg/testutil"
    21  	"github.com/matrixorigin/matrixone/pkg/vm/process"
    22  	"github.com/stretchr/testify/require"
    23  )
    24  
    25  func TestIsNot(t *testing.T) {
    26  	procs := testutil.NewProc()
    27  	cases := []struct {
    28  		name     string
    29  		proc     *process.Process
    30  		left     []bool
    31  		nsp      []uint64
    32  		right    bool
    33  		isScalar bool
    34  		expected []bool
    35  	}{
    36  		{
    37  			name:     "01 - normal test",
    38  			proc:     procs,
    39  			left:     []bool{true, false, true, false, false, true},
    40  			right:    true,
    41  			expected: []bool{false, true, false, true, true, false},
    42  			isScalar: false,
    43  		},
    44  		{
    45  			name:     "02 - normal test",
    46  			proc:     procs,
    47  			left:     []bool{true, false, true, false, false, true},
    48  			right:    false,
    49  			expected: []bool{true, false, true, false, false, true},
    50  			isScalar: false,
    51  		},
    52  		{
    53  			name:     "03 - scalar test",
    54  			proc:     procs,
    55  			left:     []bool{true},
    56  			right:    false,
    57  			expected: []bool{true},
    58  			isScalar: true,
    59  		},
    60  		{
    61  			name:     "04 - null test",
    62  			proc:     procs,
    63  			right:    true,
    64  			expected: []bool{false},
    65  			isScalar: true,
    66  		},
    67  		{
    68  			name:     "05 - null test",
    69  			proc:     procs,
    70  			right:    false,
    71  			expected: []bool{false},
    72  			isScalar: true,
    73  		},
    74  	}
    75  
    76  	for _, c := range cases {
    77  		t.Run(c.name, func(t *testing.T) {
    78  			vecs := makeIsAndIsNotTestVectors(c.left, c.right, c.isScalar)
    79  			result, err := IsNot(vecs, c.proc)
    80  			if err != nil {
    81  				t.Fatal(err)
    82  			}
    83  			col := result.Col.([]bool)
    84  			require.Equal(t, c.expected, col)
    85  			require.Equal(t, c.isScalar, result.IsScalar())
    86  		})
    87  	}
    88  }