-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
50 lines (41 loc) · 1.13 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
package main
import (
"bytes"
"testing"
)
// TestCountWords tests the count function set to count words.
func TestCountWords(t *testing.T) {
b := bytes.NewBufferString("word1 word2 word3 word4\n")
exp := 4
res := count(b, "", false, false)
if res != exp {
t.Errorf("Expected %d, got %d instead.\n", exp, res)
}
}
// TestCountLines tests the count function set to count lines.
func TestCountLines(t *testing.T) {
b := bytes.NewBufferString("word1 word2 word3\nline2\nline3 word1")
exp := 3
res := count(b, "", true, false)
if res != exp {
t.Errorf("Expected %d, got %d instead.", exp, res)
}
}
// TestCountBytes tests the count function set to count bytes.
func TestCountBytes(t *testing.T) {
b := bytes.NewBufferString("word1 word2")
exp := 11
res := count(b, "", false, true)
if res != exp {
t.Errorf("Expected %d, got %d instead.", exp, res)
}
}
// TestCountWords tests the count function set to count words.
func TestReadFile(t *testing.T) {
b := bytes.NewBufferString("")
exp := 5
res := count(b, "testdata/testfile.txt", false, false)
if res != exp {
t.Errorf("Expected %d, got %d instead.\n", exp, res)
}
}