@@ -6,11 +6,12 @@ package set
66import (
77 "context"
88 "fmt"
9- "github.com/shoenig/test/must"
10- "go.uber.org/goleak"
119 "math/rand"
1210 "strings"
1311 "testing"
12+
13+ "github.com/shoenig/test/must"
14+ "go.uber.org/goleak"
1415)
1516
1617const (
@@ -150,6 +151,17 @@ func TestTreeSet_InsertSlice(t *testing.T) {
150151 must .False (t , ts .InsertSlice (numbers ))
151152}
152153
154+ func TestTreeSet_InsertSet (t * testing.T ) {
155+ cmp := Cmp [int ]
156+
157+ ts1 := TreeSetFrom [int , Compare [int ]]([]int {1 , 3 , 5 , 7 , 9 }, cmp )
158+ ts2 := TreeSetFrom [int , Compare [int ]]([]int {1 , 2 , 3 }, cmp )
159+
160+ must .True (t , ts1 .InsertSet (ts2 ))
161+ must .Eq (t , []int {1 , 2 , 3 , 5 , 7 , 9 }, ts1 .Slice ())
162+ must .Eq (t , []int {1 , 2 , 3 }, ts2 .Slice ())
163+ }
164+
153165func TestTreeSet_Remove_int (t * testing.T ) {
154166 cmp := Cmp [int ]
155167 ts := NewTreeSet [int , Compare [int ]](cmp )
@@ -192,6 +204,40 @@ func TestTreeSet_RemoveSlice(t *testing.T) {
192204 must .Empty (t , ts )
193205}
194206
207+ func TestTreeSet_RemoveSet (t * testing.T ) {
208+ cmp := Cmp [int ]
209+
210+ ts1 := NewTreeSet [int , Compare [int ]](cmp )
211+ ts2 := NewTreeSet [int , Compare [int ]](cmp )
212+
213+ numbers := ints (size )
214+ random := shuffle (numbers )
215+ ts1 .InsertSlice (random )
216+
217+ random2 := shuffle (numbers [5 :])
218+ ts2 .InsertSlice (random2 )
219+
220+ ts1 .RemoveSet (ts2 )
221+ result := ts1 .Slice ()
222+ must .Eq (t , []int {1 , 2 , 3 , 4 , 5 }, result )
223+ }
224+
225+ func TestTreeSet_RemoveFunc (t * testing.T ) {
226+ cmp := Cmp [byte ]
227+
228+ ts := TreeSetFrom [byte , Compare [byte ]]([]byte {
229+ 'a' , 'b' , '1' , 'c' , '2' , 'd' ,
230+ }, cmp )
231+
232+ notAlpha := func (c byte ) bool {
233+ return c < 'a' || c > 'z'
234+ }
235+
236+ ts .RemoveFunc (notAlpha )
237+
238+ must .Eq (t , []byte {'a' , 'b' , 'c' , 'd' }, ts .Slice ())
239+ }
240+
195241func TestTreeSet_Contains (t * testing.T ) {
196242 t .Run ("empty" , func (t * testing.T ) {
197243 ts := NewTreeSet [int , Compare [int ]](Cmp [int ])
0 commit comments