feat: add Rotate for string

This commit is contained in:
dudaodong committed 2024-09-03 16:35:38 +08:00
1 parent 63216d9b1c
commit 601df5dc12
5 files changed
+152 -15

No files matched your search

+29 -4
View File
@@ -710,9 +710,9 @@ func TestEllipsis(t *testing.T) {
assert := internal.NewAssert(t, "TestEllipsis")
tests := []struct {
input string
length int
want string
input string
length int
expected string
}{
{"", 0, ""},
{"hello world", 0, ""},
@@ -725,7 +725,7 @@ func TestEllipsis(t *testing.T) {
}
for _, tt := range tests {
assert.Equal(tt.want, Ellipsis(tt.input, tt.length))
assert.Equal(tt.expected, Ellipsis(tt.input, tt.length))
}
}
@@ -741,3 +741,28 @@ func TestShuffle(t *testing.T) {
shuffledStr := Shuffle(str)
assert.Equal(5, len(shuffledStr))
}
func TestRotate(t *testing.T) {
t.Parallel()
assert := internal.NewAssert(t, "TestRotate")
tests := []struct {
input string
shift int
expected string
}{
{"", 1, ""},
{"a", 0, "a"},
{"a", 1, "a"},
{"a", -1, "a"},
{"Hello", -2, "lloHe"},
{"Hello", 1, "oHell"},
{"Hello, world!", 3, "ld!Hello, wor"},
}
for _, tt := range tests {
assert.Equal(tt.expected, Rotate(tt.input, tt.shift))
}
}