-
Notifications
You must be signed in to change notification settings - Fork 65
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
Add intersect util method for StringSet #4
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -97,3 +97,46 @@ func TestStringSet_ToSlice(t *testing.T) { | |
assert.True(t, testSet.Contains(item)) | ||
} | ||
} | ||
|
||
func TestStringSet_Intersect(t *testing.T) { | ||
testSet := &stringSet{ | ||
m: make(map[string]bool), | ||
} | ||
|
||
testSet1 := &stringSet{ | ||
m: make(map[string]bool), | ||
} | ||
|
||
testItems := []string{ | ||
"testitem1", | ||
"testitem2", | ||
} | ||
|
||
// Add testItems to testSet | ||
for _, item := range testItems { | ||
testSet.m[item] = true | ||
} | ||
|
||
testItems1 := []string{ | ||
"testitem1", | ||
"testitem2", | ||
"testitem3", | ||
} | ||
|
||
// Add testItems1 to testSet1 | ||
for _, item := range testItems1 { | ||
testSet1.m[item] = true | ||
} | ||
|
||
// Intersect the two stringSet | ||
intersection := testSet.Intersect(testSet1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use test table and add more unit tests such as
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, done. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use table driven tests, rather than creating separate tests. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cool stuff! |
||
|
||
items := intersection.ToSlice() | ||
|
||
for _, item := range items { | ||
if item == "testitem3" { | ||
assert.False(t, testSet.Contains(item)) | ||
} | ||
assert.True(t, testSet.Contains(item)) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use string set Add method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can do it but then tests will be different from previous ones.