-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add unit test for RemoveRepeatedElementsInLi (#1223)
Co-authored-by: sweep-ai[bot] <128439645+sweep-ai[bot]@users.noreply.github.com>
- Loading branch information
1 parent
5e7e619
commit 1c1f2a9
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package cache_test | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/openimsdk/open-im-server/v3/pkg/common/db/cache" | ||
) | ||
|
||
func TestRemoveRepeatedElementsInList(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
input []string | ||
expected []string | ||
}{ | ||
{ | ||
name: "No duplicates", | ||
input: []string{"a", "b", "c"}, | ||
expected: []string{"a", "b", "c"}, | ||
}, | ||
{ | ||
name: "All duplicates", | ||
input: []string{"a", "a", "a"}, | ||
expected: []string{"a"}, | ||
}, | ||
{ | ||
name: "Some duplicates", | ||
input: []string{"a", "b", "a", "c", "b"}, | ||
expected: []string{"a", "b", "c"}, | ||
}, | ||
{ | ||
name: "Empty list", | ||
input: []string{}, | ||
expected: []string{}, | ||
}, | ||
{ | ||
name: "Single element", | ||
input: []string{"a"}, | ||
expected: []string{"a"}, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
result := cache.RemoveRepeatedElementsInList(tc.input) | ||
if !reflect.DeepEqual(result, tc.expected) { | ||
t.Errorf("expected %v, got %v", tc.expected, result) | ||
} | ||
}) | ||
} | ||
} |