|
@@ -1,18 +1,18 @@
|
|
|
package cos
|
|
|
|
|
|
import (
|
|
|
+ "fmt"
|
|
|
"strings"
|
|
|
"testing"
|
|
|
"unicode/utf8"
|
|
|
- "fmt"
|
|
|
)
|
|
|
|
|
|
func checkChunks(text string, size int) (*chunkOfSize, int, error) {
|
|
|
- chunk := NewChunkOfSize(testText, size)
|
|
|
+ chunk := NewChunkOfSize(testText, size)
|
|
|
if chunk == nil {
|
|
|
return nil, -1, fmt.Errorf("Chunk is nil!")
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
count := 0
|
|
|
|
|
|
for {
|
|
@@ -22,24 +22,24 @@ func checkChunks(text string, size int) (*chunkOfSize, int, error) {
|
|
|
}
|
|
|
|
|
|
if utf8.RuneCountInString(text) > size {
|
|
|
- return chunk, -1, fmt.Errorf("'%s'\nis longer than %d", text, size)
|
|
|
+ return chunk, -1, fmt.Errorf("'%s'\nis longer than %d", text, size)
|
|
|
}
|
|
|
|
|
|
count++
|
|
|
}
|
|
|
|
|
|
- return chunk, count, nil
|
|
|
+ return chunk, count, nil
|
|
|
}
|
|
|
|
|
|
func Test4ChunksOf100(t *testing.T) {
|
|
|
size := 100
|
|
|
- expectedChunks := 4
|
|
|
-
|
|
|
+ expectedChunks := 4
|
|
|
+
|
|
|
chunk, count, err := checkChunks(testText, size)
|
|
|
- if err != nil {
|
|
|
- t.Fatal(err)
|
|
|
- }
|
|
|
-
|
|
|
+ if err != nil {
|
|
|
+ t.Fatal(err)
|
|
|
+ }
|
|
|
+
|
|
|
if count != expectedChunks {
|
|
|
t.Fatal("There should be", expectedChunks, "chunks, but have", count)
|
|
|
}
|
|
@@ -54,9 +54,9 @@ func TestWordBiggerThanLimit(t *testing.T) {
|
|
|
chunk := NewChunkOfSize(testText, size)
|
|
|
|
|
|
text := chunk.Next()
|
|
|
- if text != "" {
|
|
|
- t.Fatal("Chunk should be empty, but is:", text)
|
|
|
- }
|
|
|
+ if text != "" {
|
|
|
+ t.Fatal("Chunk should be empty, but is:", text)
|
|
|
+ }
|
|
|
|
|
|
if chunk.Success() || len(chunk.GetErrors()) == 0 {
|
|
|
t.Fatal("There should be errors!")
|
|
@@ -65,25 +65,25 @@ func TestWordBiggerThanLimit(t *testing.T) {
|
|
|
|
|
|
func TestTextShorterThanLimit(t *testing.T) {
|
|
|
size := 400
|
|
|
- chunk := NewChunkOfSize(shorterText, size)
|
|
|
+ chunk := NewChunkOfSize(shorterText, size)
|
|
|
if chunk != nil {
|
|
|
t.Fatal("Chunk should be nil!")
|
|
|
}
|
|
|
}
|
|
|
|
|
|
func checkWord(word string) bool {
|
|
|
- for i := range validWords {
|
|
|
- if word == validWords[i] {
|
|
|
- return true
|
|
|
- }
|
|
|
- }
|
|
|
+ for i := range validWords {
|
|
|
+ if word == validWords[i] {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- return false
|
|
|
+ return false
|
|
|
}
|
|
|
|
|
|
-func TestWordsNotCut(t *testing.T){
|
|
|
- size := 12
|
|
|
- chunk := NewChunkOfSize(shorterText, size)
|
|
|
+func TestWordsNotCut(t *testing.T) {
|
|
|
+ size := 12
|
|
|
+ chunk := NewChunkOfSize(shorterText, size)
|
|
|
if chunk == nil {
|
|
|
t.Fatal("Chunk shouldn't be nil!")
|
|
|
}
|
|
@@ -95,10 +95,10 @@ func TestWordsNotCut(t *testing.T){
|
|
|
}
|
|
|
|
|
|
words := strings.Split(text, " ")
|
|
|
- for i := range words {
|
|
|
- if !checkWord(words[i]) {
|
|
|
- t.Fatal(words[i], "isn't a valid word!")
|
|
|
- }
|
|
|
- }
|
|
|
+ for i := range words {
|
|
|
+ if !checkWord(words[i]) {
|
|
|
+ t.Fatal(words[i], "isn't a valid word!")
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
-}
|
|
|
+}
|