Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unit test for go/sets/set.go #14973

Merged
merged 5 commits into from
Jan 25, 2024
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions go/sets/set_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
Copyright 2024 The Vitess Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package sets

import (
"testing"

Comment on lines +17 to +21
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

license header is missing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added.

"github.com/stretchr/testify/assert"
)

func TestInsert(t *testing.T) {
testSet := New[int](1, 2, 3)
testSet.Insert(4, 5, 6)
compareSet := New[int](1, 2, 3, 4, 5, 6)
assert.Equal(t, testSet, compareSet)
}

func TestDelete(t *testing.T) {
testSet := New[int](1, 2, 3, 4, 5, 6)
testSet.Delete(1, 5)
compareSet := New[int](2, 3, 4, 6)
assert.Equal(t, testSet, compareSet)
testSet.Delete(2, 3, 4, 6)
assert.Empty(t, testSet)
}

func TestHas(t *testing.T) {
testSet := New[int](1, 2, 3)
assert.True(t, testSet.Has(3))
assert.False(t, testSet.Has(-1))
}

func TestHasAny(t *testing.T) {
testSet := New[int](1, 2, 3)
assert.True(t, testSet.HasAny(1, 10, 11))
assert.False(t, testSet.HasAny(-1, 10, 11))
}

func TestDifference(t *testing.T) {
testSet := New[int](1, 2, 3)
compareSet := New[int](-1, -2, 1, 2, 3)
diffSet := New[int](-1, -2)
assert.Equal(t, diffSet, compareSet.Difference(testSet))
}

func TestIntersection(t *testing.T) {
setA := New[int](1, 2, 3)
setB := New[int](1, 2, 8, 9, 10)
expectedSet := New[int](1, 2)
assert.Equal(t, expectedSet, setA.Intersection(setB))
}

func TestEqual(t *testing.T) {
testSet := New[int](1, 2, 3, 4, 5, 6)
compareSet := New[int](1, 2, 3, 4, 5, 6)
assert.True(t, testSet.Equal(compareSet))
compareSet.Insert(-1, -2)
assert.False(t, testSet.Equal(compareSet))
}

func TestLen(t *testing.T) {
testSet := New[int](1, 2, 3)
assert.Equal(t, testSet.Len(), 3)
}
Loading