-
Notifications
You must be signed in to change notification settings - Fork 1
/
countBuffer_test.go
79 lines (72 loc) · 2.2 KB
/
countBuffer_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
package main
import (
"bufio"
"strings"
"testing"
)
type fixtures struct {
input string
words int
lines int
chars int
}
// Each of the test case results below are based on the output of `wc` program
// on a plain text file with the string contents. I'm trading off actual
// correctness in favour of verifiable comparision between wc and my wc program.
// For example, one would expect a hyphenated word to count as one, but the
// *nix wc program counts them as two words.
var tests = []fixtures{
{"this is a test string", 5, 0, 21},
{"this is a test string ", 5, 0, 22},
{" this is a test string", 5, 0, 22},
{"this is a test string", 5, 0, 36},
{"this is a test string", 5, 0, 24},
{"this is a test string\nthis is another strirg", 9, 1, 44},
{"this is a test string\n\n\n\n\n\nthis is another string", 9, 6, 49},
{"this is a test string\n this is another string", 9, 1, 45},
{"this is a test str-\ning this is another string", 10, 1, 46},
{"this is a test string \n this is another string", 9, 1, 46},
{"this * * ***** is a test string", 8, 0, 31},
{". . . . . . . . . .", 10, 0, 19},
{`Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At
vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren,
no sea takimata sanctus est Lorem ipsum dolor sit amet.`, 50, 3, 298},
{"é", 1, 0, 1},
{"😀", 1, 0, 1},
{"👂🏼", 1, 0, 2},
{"😀😀\n👂🏼", 2, 1, 5},
{"😀 😀\n👂🏼", 3, 1, 6},
}
func TestCount(t *testing.T) {
for i, fixture := range tests {
count := processStream(bufio.NewScanner(strings.NewReader(fixture.input)))
if count.words != fixture.words {
t.Error(
"For test number", i+1,
"expected", fixture.words,
"words but",
"got", count.words,
"words",
)
}
if count.lines != fixture.lines {
t.Error(
"For test number", i+1,
"expected", fixture.lines,
"lines but",
"got", count.lines,
"lines",
)
}
if count.chars != fixture.chars {
t.Error(
"For test number", i+1,
"expected", fixture.chars,
"characters but",
"got", count.chars,
"characters",
)
}
}
}