github.com/dolthub/dolt/go@v0.40.5-0.20240520175717-68db7794bea6/libraries/utils/set/uint64set_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 set 16 17 import ( 18 "testing" 19 20 "github.com/stretchr/testify/assert" 21 ) 22 23 func TestNewUint64Set(t *testing.T) { 24 initData := []uint64{0, 1, 2, 3} 25 us := NewUint64Set(initData) 26 27 // test .Size() 28 assert.Equal(t, 4, us.Size()) 29 30 // test .Contains() 31 for _, id := range initData { 32 assert.True(t, us.Contains(id)) 33 } 34 assert.False(t, us.Contains(19)) 35 36 // test .ContainsAll() 37 assert.True(t, us.ContainsAll([]uint64{0, 1})) 38 assert.False(t, us.ContainsAll([]uint64{0, 1, 2, 19})) 39 40 // test .Add() 41 us.Add(6) 42 assert.True(t, us.Contains(6)) 43 assert.Equal(t, 5, us.Size()) 44 for _, id := range initData { 45 assert.True(t, us.Contains(id)) 46 } 47 assert.True(t, us.ContainsAll(append(initData, 6))) 48 49 // test .Remove() 50 us.Remove(0) 51 assert.False(t, us.Contains(0)) 52 assert.Equal(t, 4, us.Size()) 53 54 us.Remove(19) 55 assert.Equal(t, 4, us.Size()) 56 57 // test .AsSlice() 58 s := us.AsSlice() 59 assert.Equal(t, []uint64{1, 2, 3, 6}, s) 60 61 us.Add(4) 62 s = us.AsSlice() 63 assert.Equal(t, []uint64{1, 2, 3, 4, 6}, s) 64 }