2022-09-27 23:52:13 +00:00
|
|
|
package set
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
2022-09-28 04:26:44 +00:00
|
|
|
"sort"
|
2022-09-27 23:52:13 +00:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestNew(t *testing.T) {
|
|
|
|
type args struct {
|
|
|
|
v []string
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
args args
|
|
|
|
want Set[string]
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "new",
|
|
|
|
args: args{
|
|
|
|
v: []string{"a", "b", "c"},
|
|
|
|
},
|
|
|
|
want: Set[string]{
|
|
|
|
mp: map[string]struct{}{
|
|
|
|
"a": {},
|
|
|
|
"b": {},
|
|
|
|
"c": {},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "new empty",
|
|
|
|
args: args{
|
|
|
|
v: []string{},
|
|
|
|
},
|
|
|
|
want: Set[string]{
|
|
|
|
mp: map[string]struct{}{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
if got := New(tt.args.v...); !reflect.DeepEqual(got, tt.want) {
|
|
|
|
t.Errorf("New() = %v, want %v", got, tt.want)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSet_Insert(t *testing.T) {
|
|
|
|
type args struct {
|
|
|
|
v []string
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
s Set[string]
|
|
|
|
args args
|
|
|
|
want Set[string]
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "insert",
|
|
|
|
s: Set[string]{
|
|
|
|
mp: map[string]struct{}{
|
|
|
|
"a": {},
|
|
|
|
"b": {},
|
|
|
|
"c": {},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
v: []string{"d", "e", "f"},
|
|
|
|
},
|
|
|
|
want: Set[string]{
|
|
|
|
mp: map[string]struct{}{
|
|
|
|
"a": {},
|
|
|
|
"b": {},
|
|
|
|
"c": {},
|
|
|
|
"d": {},
|
|
|
|
"e": {},
|
|
|
|
"f": {},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "insert empty",
|
|
|
|
s: Set[string]{
|
|
|
|
mp: map[string]struct{}{},
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
v: []string{"a", "b", "c"},
|
|
|
|
},
|
|
|
|
want: Set[string]{
|
|
|
|
mp: map[string]struct{}{
|
|
|
|
"a": {},
|
|
|
|
"b": {},
|
|
|
|
"c": {},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
tt.s.Insert(tt.args.v...)
|
|
|
|
if !reflect.DeepEqual(tt.s, tt.want) {
|
|
|
|
t.Errorf("Set.Insert() = %v, want %v", tt.s, tt.want)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSet_Delete(t *testing.T) {
|
|
|
|
type args struct {
|
|
|
|
v []string
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
s Set[string]
|
|
|
|
args args
|
|
|
|
want Set[string]
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "insert",
|
|
|
|
s: Set[string]{
|
|
|
|
mp: map[string]struct{}{
|
|
|
|
"a": {},
|
|
|
|
"b": {},
|
|
|
|
"c": {},
|
|
|
|
"d": {},
|
|
|
|
"e": {},
|
|
|
|
"f": {},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
v: []string{"d", "e", "f"},
|
|
|
|
},
|
|
|
|
want: Set[string]{
|
|
|
|
mp: map[string]struct{}{
|
|
|
|
"a": {},
|
|
|
|
"b": {},
|
|
|
|
"c": {},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "delete empty",
|
|
|
|
s: Set[string]{
|
|
|
|
mp: map[string]struct{}{},
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
v: []string{},
|
|
|
|
},
|
|
|
|
want: Set[string]{
|
|
|
|
mp: map[string]struct{}{},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
tt.s.Remove(tt.args.v...)
|
|
|
|
if !reflect.DeepEqual(tt.s, tt.want) {
|
|
|
|
t.Errorf("Set.Delete() = %v, want %v", tt.s, tt.want)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSet_ContainsAll(t *testing.T) {
|
|
|
|
type args struct {
|
|
|
|
v []string
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
s Set[string]
|
|
|
|
args args
|
|
|
|
want bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "contains",
|
|
|
|
s: Set[string]{
|
|
|
|
mp: map[string]struct{}{
|
|
|
|
"a": {},
|
|
|
|
"b": {},
|
|
|
|
"c": {},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
v: []string{"a", "b", "c"},
|
|
|
|
},
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "contains empty",
|
|
|
|
s: Set[string]{
|
|
|
|
mp: map[string]struct{}{},
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
v: []string{},
|
|
|
|
},
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "not contains",
|
|
|
|
s: Set[string]{
|
|
|
|
mp: map[string]struct{}{
|
|
|
|
"a": {},
|
|
|
|
"b": {},
|
|
|
|
"c": {},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
args: args{
|
|
|
|
v: []string{"d", "e", "f"},
|
|
|
|
},
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
if got := tt.s.ContainsAll(tt.args.v...); got != tt.want {
|
|
|
|
t.Errorf("Set.ContainsAll() = %v, want %v", got, tt.want)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSet_Slice(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
s Set[string]
|
|
|
|
want []string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "slice",
|
|
|
|
s: Set[string]{
|
|
|
|
mp: map[string]struct{}{
|
|
|
|
"a": {},
|
|
|
|
"b": {},
|
|
|
|
"c": {},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
want: []string{"a", "b", "c"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "slice empty",
|
|
|
|
s: Set[string]{
|
|
|
|
mp: map[string]struct{}{},
|
|
|
|
},
|
|
|
|
want: []string{},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2022-09-28 04:26:44 +00:00
|
|
|
got := tt.s.Slice()
|
|
|
|
|
|
|
|
sort.Strings(got)
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(got, tt.want) {
|
2022-09-27 23:52:13 +00:00
|
|
|
t.Errorf("Set.Slice() = %v, want %v", got, tt.want)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|