github.com/jxskiss/gopkg/v2@v2.14.9-0.20240514120614-899f3e7952b4/collection/set/compat_test.go (about)

     1  package set
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  func TestInt(t *testing.T) {
    10  	s := NewInt(1, 3, 5)
    11  	_ = NewIntWithSize(3) // coverage
    12  	assert.Equal(t, 3, s.Size())
    13  	assert.True(t, s.Contains(1))
    14  	assert.False(t, s.Contains(2))
    15  }
    16  
    17  func TestInt64(t *testing.T) {
    18  	s := NewInt64(1, 3, 5)
    19  	_ = NewInt64WithSize(3) // coverage
    20  	assert.Equal(t, 3, s.Size())
    21  	assert.True(t, s.Contains(1))
    22  	assert.False(t, s.Contains(2))
    23  }
    24  
    25  func TestInt32(t *testing.T) {
    26  	s := NewInt32(1, 3, 5)
    27  	_ = NewInt32WithSize(3) // coverage
    28  	assert.Equal(t, 3, s.Size())
    29  	assert.True(t, s.Contains(1))
    30  	assert.False(t, s.Contains(2))
    31  }
    32  
    33  func TestString(t *testing.T) {
    34  	s1 := NewString("a", "b", "c")
    35  	s2 := NewStringWithSize(4)
    36  	slice := []string{"c", "d", "e"}
    37  	s2.Add(slice...)
    38  
    39  	assert.Equal(t, 2, s1.Diff(s2).Size())
    40  	assert.Equal(t, 2, s1.DiffSlice(slice).Size())
    41  	assert.Equal(t, 1, s1.Intersect(s2).Size())
    42  	assert.Equal(t, 1, s1.IntersectSlice(slice).Size())
    43  	assert.Equal(t, 5, s1.Union(s2).Size())
    44  	assert.Equal(t, 5, s1.UnionSlice(slice).Size())
    45  
    46  	s1.Del("a")
    47  	assert.ElementsMatch(t, []string{"b", "c"}, s1.Slice())
    48  	assert.ElementsMatch(t, []string{"c"}, s1.FilterInclude(slice))
    49  	assert.ElementsMatch(t, []string{"d", "e"}, s1.FilterExclude(slice))
    50  }