-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: 🌲 Harry 🌊 John 🏔 <[email protected]>
- Loading branch information
1 parent
27412d2
commit 760f2c5
Showing
4 changed files
with
121 additions
and
24 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
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
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
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,95 @@ | ||
// Copyright (c) The Thanos Authors. | ||
// Licensed under the Apache License 2.0. | ||
|
||
package strutil | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/efficientgo/core/testutil" | ||
) | ||
|
||
func TestMergeSlices(t *testing.T) { | ||
testCases := map[string]struct { | ||
slices [][]string | ||
limit int | ||
expected []string | ||
}{ | ||
"empty slice": { | ||
slices: [][]string{ | ||
{}, | ||
}, | ||
expected: []string{}, | ||
}, | ||
"single slice with limit": { | ||
slices: [][]string{ | ||
{"a", "b", "c", "d"}, | ||
}, | ||
limit: 2, | ||
expected: []string{"a", "b"}, | ||
}, | ||
"multiple slices with limit": { | ||
slices: [][]string{ | ||
{"a", "b", "d", "f"}, | ||
{"c", "e", "g"}, | ||
{"r", "s", "t"}, | ||
}, | ||
limit: 4, | ||
expected: []string{"a", "b", "c", "d"}, | ||
}, | ||
"multiple slices without limit": { | ||
slices: [][]string{ | ||
{"a", "b", "d", "f"}, | ||
{"c", "e", "g"}, | ||
{"r", "s"}, | ||
}, | ||
expected: []string{"a", "b", "c", "d", "e", "f", "g", "r", "s"}, | ||
}, | ||
} | ||
|
||
for tcName, tc := range testCases { | ||
t.Run(tcName, func(t *testing.T) { | ||
res := MergeSlices(tc.limit, tc.slices...) | ||
testutil.Equals(t, tc.expected, res) | ||
}) | ||
} | ||
} | ||
|
||
func TestMergeUnsortedSlices(t *testing.T) { | ||
testCases := map[string]struct { | ||
slices [][]string | ||
limit int | ||
expected []string | ||
}{ | ||
"empty slice": { | ||
slices: [][]string{ | ||
{}, | ||
}, | ||
expected: []string{}, | ||
}, | ||
"multiple slices without limit": { | ||
slices: [][]string{ | ||
{"d", "c", "b", "a"}, | ||
{"f", "g", "c"}, | ||
{"s", "r", "e"}, | ||
}, | ||
expected: []string{"a", "b", "c", "d", "e", "f", "g", "r", "s"}, | ||
}, | ||
"multiple slices with limit": { | ||
slices: [][]string{ | ||
{"d", "c", "b", "a"}, | ||
{"f", "g", "c"}, | ||
{"s", "r", "e"}, | ||
}, | ||
limit: 5, | ||
expected: []string{"a", "b", "c", "d", "e"}, | ||
}, | ||
} | ||
|
||
for tcName, tc := range testCases { | ||
t.Run(tcName, func(t *testing.T) { | ||
res := MergeUnsortedSlices(tc.limit, tc.slices...) | ||
testutil.Equals(t, tc.expected, res) | ||
}) | ||
} | ||
} |