feat(aa-log): add some util functions.

This commit is contained in:
Alexandre Pujol 2024-09-10 18:38:59 +01:00
parent 49b8967bb2
commit e4f963f30f
No known key found for this signature in database
GPG key ID: C5469996F0DF68EC
4 changed files with 201 additions and 102 deletions

View file

@ -38,74 +38,6 @@ func TestDecodeHexInString(t *testing.T) {
}
}
func TestRemoveDuplicate(t *testing.T) {
tests := []struct {
name string
inlist []string
want []string
}{
{
name: "Duplicate",
inlist: []string{"foo", "bar", "foo", "bar", ""},
want: []string{"foo", "bar"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := RemoveDuplicate(tt.inlist); !reflect.DeepEqual(got, tt.want) {
t.Errorf("RemoveDuplicate() = %v, want %v", got, tt.want)
}
})
}
}
func TestIntersect(t *testing.T) {
tests := []struct {
name string
list1 []int
list2 []int
want []int
}{
{
name: "1",
list1: []int{0, 1, 2, 3, 4, 5},
list2: []int{0, 2},
want: []int{0, 2},
},
{
name: "2",
list1: []int{0, 1, 2, 3, 4, 5},
list2: []int{0, 6},
want: []int{0},
},
{
name: "3",
list1: []int{0, 1, 2, 3, 4, 5},
list2: []int{-1, 6},
want: []int{},
},
{
name: "4",
list1: []int{0, 6},
list2: []int{0, 1, 2, 3, 4, 5},
want: []int{0},
},
{
name: "5",
list1: []int{0, 6, 0},
list2: []int{0, 1, 2, 3, 4, 5},
want: []int{0},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := Intersect(tt.list1, tt.list2); !reflect.DeepEqual(got, tt.want) {
t.Errorf("Intersect() = %v, want %v", got, tt.want)
}
})
}
}
func TestToRegexRepl(t *testing.T) {
tests := []struct {
name string