Skip to content

Commit

Permalink
chore: add tests for SplitStringIntoChunks
Browse files Browse the repository at this point in the history
  • Loading branch information
freak12techno committed May 19, 2024
1 parent cb4ded3 commit e8a9d61
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions pkg/utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package utils

import (
"main/pkg/constants"
"math/rand"
"net/http"
"testing"
"time"
Expand All @@ -11,6 +12,16 @@ import (
"github.com/stretchr/testify/assert"
)

func StringOfRandomLength(n int) string {
var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")

b := make([]rune, n)
for i := range b {
b[i] = letters[rand.Intn(len(letters))]
}
return string(b)
}

func TestFilter(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -111,3 +122,28 @@ func TestMustMarshallValid(t *testing.T) {
content := MustMarshal(str)
assert.Equal(t, []byte("\"test\""), content)
}

func TestSplitStringIntoChunksLessThanOneChunk(t *testing.T) {
t.Parallel()

str := StringOfRandomLength(10)
chunks := SplitStringIntoChunks(str, 20)
assert.Len(t, chunks, 1, "There should be 1 chunk!")
}

func TestSplitStringIntoChunksExactlyOneChunk(t *testing.T) {
t.Parallel()

str := StringOfRandomLength(10)
chunks := SplitStringIntoChunks(str, 10)

assert.Len(t, chunks, 1, "There should be 1 chunk!")
}

func TestSplitStringIntoChunksMoreChunks(t *testing.T) {
t.Parallel()

str := "aaaa\nbbbb\ncccc\ndddd\neeeee\n"
chunks := SplitStringIntoChunks(str, 10)
assert.Len(t, chunks, 3, "There should be 3 chunks!")
}

0 comments on commit e8a9d61

Please sign in to comment.