-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
89 lines (71 loc) · 2.23 KB
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package main
import (
"os"
"reflect"
"testing"
)
const testFile string = "test.txt"
func TestFileToBytes(t *testing.T) {
fileData := fileToBytes(testFile)
fileBytes, err := os.ReadFile(testFile)
if err != nil {
t.Error("Can not find test data")
}
equalBytes := reflect.DeepEqual(fileData, fileBytes)
if equalBytes != true {
t.Errorf("FileToBytes(%s), FAILED. Expected %s got %s \n", testFile, fileBytes, fileData)
} else {
t.Logf("FileToBytes(%s), PASSED.\n", testFile)
}
}
func TestByteCount(t *testing.T) {
fileBytes := fileToBytes(testFile)
byteCount := countBytes(fileBytes)
byteCountExpected := 342190
if byteCount != byteCountExpected {
t.Errorf("countBytes(%s), FAILED. Expected %d got %d \n", testFile, byteCountExpected, byteCount)
} else {
t.Logf("countBytes(%s), PASSED.\n", testFile)
}
}
func TestLineCount(t *testing.T) {
fileBytes := fileToBytes(testFile)
lineCount := countLines(fileBytes)
lineCountExpected := 7145
if lineCount != lineCountExpected {
t.Errorf("countLines(%s), FAILED. Expected %d got %d \n", testFile, lineCountExpected, lineCount)
} else {
t.Logf("countLines(%s), PASSED.\n", testFile)
}
}
func TestWordCount(t *testing.T) {
fileBytes := fileToBytes(testFile)
wordCount := countWords(fileBytes)
wordCountExpected := 58164
if wordCount != wordCountExpected {
t.Errorf("countWords(%s), FAILED. Expected %d got %d \n", testFile, wordCountExpected, wordCount)
} else {
t.Logf("countWords(%s), PASSED.\n", testFile)
}
}
func TestCharCount(t *testing.T) {
fileBytes := fileToBytes(testFile)
charCount := countChars(fileBytes)
charCountExpected := 339292
if charCount != charCountExpected {
t.Errorf("countChars(%s), FAILED. Expected %d got %d \n", testFile, charCountExpected, charCount)
} else {
t.Logf("countChars(%s), PASSED.\n", testFile)
}
}
func TestStripTabandSpaceFromLine(t *testing.T) {
line := "hello world. today."
outputSlice := []string{"hello", "world.", "today."}
stripLine := stripTabAndSpaceFromLine(line)
isEqual := reflect.DeepEqual(outputSlice, stripLine)
if isEqual != true {
t.Errorf("stripTabAndSpaceFromLine(%s), FAILED. Expected %v got %v \n", line, outputSlice, stripLine)
} else {
t.Logf("stripTabAndSpaceFromLine(%s), PASSED.\n", line)
}
}