github.com/hasnat/dolt/go@v0.0.0-20210628190320-9eb5d843fbb7/libraries/doltcore/sqle/setalgebra/set_test.go (about)

     1  // Copyright 2020 Dolthub, Inc.
     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 setalgebra
    16  
    17  import (
    18  	"testing"
    19  
    20  	"github.com/stretchr/testify/assert"
    21  
    22  	"github.com/dolthub/dolt/go/store/types"
    23  )
    24  
    25  func TestEmptySet(t *testing.T) {
    26  	empty := EmptySet{}
    27  	testVal := mustFiniteSet(NewFiniteSet(types.Format_Default, types.String("test")))
    28  
    29  	union, err := empty.Union(testVal)
    30  	assert.NoError(t, err)
    31  
    32  	assert.Equal(t, testVal, union)
    33  
    34  	intersection, err := empty.Intersect(testVal)
    35  	assert.NoError(t, err)
    36  
    37  	assert.Equal(t, empty, intersection)
    38  }
    39  
    40  func TestUniversalSet(t *testing.T) {
    41  	universal := UniversalSet{}
    42  	testVal := mustFiniteSet(NewFiniteSet(types.Format_Default, types.String("test")))
    43  
    44  	union, err := universal.Union(testVal)
    45  	assert.NoError(t, err)
    46  
    47  	assert.Equal(t, universal, union)
    48  
    49  	intersection, err := universal.Intersect(testVal)
    50  	assert.NoError(t, err)
    51  
    52  	assert.Equal(t, testVal, intersection)
    53  }