-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
37 lines (30 loc) · 870 Bytes
/
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
package main
import (
"bytes"
"testing"
)
// To be extended with more test cases
func TestCW(t *testing.T) {
mockFile := bytes.NewReader([]byte("Hello\nworld\nthe world\nis a beautiful place"))
result, err := getStatsFromReader(mockFile)
requireNoError(t, err)
t.Log("total_lines", result.TotalLines)
t.Log("total_characters", result.TotalCharacters)
t.Log("total_bytes", result.TotalBytes)
t.Log("total_words", result.TotalWords)
requireEqual(t, 4, result.TotalLines)
requireEqual(t, 8, result.TotalWords)
requireEqual(t, 42, result.TotalCharacters)
requireEqual(t, 42, result.TotalBytes)
}
func requireNoError(t *testing.T, err error) {
if err != nil {
t.FailNow()
}
}
func requireEqual[T comparable](t *testing.T, expected T, actual T) {
if expected != actual {
t.Logf("expected %v but instead got %v", expected, actual)
t.FailNow()
}
}