Permalink
Browse files

Adding utils and test file

  • Loading branch information...
MohamedBassem committed Jul 6, 2015
1 parent 9e9a6e6 commit 5ba289a0808b8b94cb2790f5838abff2b1ddeb11
Showing with 28 additions and 0 deletions.
  1. +12 −0 utils.go
  2. +16 −0 utils_test.go
View
@@ -0,0 +1,12 @@
package getaredis
import "math/rand"
func generateRandomString(length int) string {
var ret string
runes := []rune("abcdefghijklmnopqrstuvwxyz0123456789")
for i := 0; i < length; i++ {
ret += string(runes[rand.Intn(len(runes))])
}
return ret
}
View
@@ -0,0 +1,16 @@
package getaredis
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestGenerateRandomString(t *testing.T) {
tests := [...]int{0, 10, 20, 30}
for test := range tests {
str := generateRandomString(test)
assert.Equal(t, test, len(str), "String should be equal the specified length")
}
}

0 comments on commit 5ba289a

Please sign in to comment.