Browse Source

Added TestWordsNotCut

Piotr Czajkowski 3 months ago
parent
commit
fd2efab153
2 changed files with 34 additions and 1 deletions
  1. 29 0
      chunkOfSize_test.go
  2. 5 1
      testText.go

+ 29 - 0
chunkOfSize_test.go

@@ -75,4 +75,33 @@ func TestTextShorterThanLimit(t *testing.T) {
 	if !chunk.Success() {
 		t.Fatal("There were errors:\n", strings.Join(chunk.GetErrors(), "\n"))
 	}
+}
+
+func checkWord(word string) bool {
+  for i := range validWords {
+    if word == validWords[i] {
+      return true
+    }
+  }
+
+  return false
+}
+
+func TestWordsNotCut(t *testing.T){
+  size := 12
+  chunk := NewChunkOfSize(shorterText, size)
+
+	for {
+		text := chunk.Next()
+		if text == "" {
+			break
+		}
+
+		words := strings.Split(text, " ")
+    for i := range words {
+      if !checkWord(words[i]) {
+        t.Fatal(words[i], "isn't a valid word!")
+      }
+    }
+	}
 }

+ 5 - 1
testText.go

@@ -1,3 +1,7 @@
 package cos
 
-var testText string = "Fuga ullam porro iusto est quaerat accusantium laboriosam consequuntur, a optio repellendus error! corrupti neque, quasi suscipit aliquam architecto ratione delectus. placeat dicta saepe cumque. Ipsam officiis asperiores rerum vel nam beatae ipsa tempora! eius! officia, deserunt, vero voluptatum ad"
+var testText string = "Fuga ullam porro iusto est quaerat accusantium laboriosam consequuntur, a optio repellendus error! corrupti neque, quasi suscipit aliquam architecto ratione delectus. placeat dicta saepe cumque. Ipsam officiis asperiores rerum vel nam beatae ipsa tempora! eius! officia, deserunt, vero voluptatum ad"
+
+var shorterText string = "Lorem ipsum dolor. Lorem ipsum dolor."
+
+var validWords []string = []string{"Lorem", "ipsum", "dolor."}