-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
74 lines (64 loc) · 1.56 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
package main
import (
"testing"
"wcgo/utilities"
)
func TestCountLines(t *testing.T) {
expected := 7145 // Replace with the actual line count of your test.txt file
file := utilities.ReadFile(t, "test.txt")
defer file.Close()
result, err := utilities.CountLines(file)
if err != nil {
t.Fatalf("Error counting lines: %v", err)
}
if result != expected {
t.Errorf("Expected %d lines, but got %d", expected, result)
}
}
func TestCountWords(t *testing.T) {
expected := 58164
file := utilities.ReadFile(t, "test.txt")
defer file.Close()
result, err := utilities.CountWords(file)
if err != nil {
t.Error(err)
return
}
if result != expected {
t.Errorf("Expected %d, got %d", expected, result)
}
}
func TestCountCharacters(t *testing.T) {
expected := 339292
file := utilities.ReadFile(t, "test.txt")
defer file.Close()
result, err := utilities.CountCharacters(file)
if err != nil {
t.Error(err)
}
if result != expected {
t.Errorf("Expected %d, got %d", expected, result)
}
}
func TestCountAll(t *testing.T) {
expectedLines := 7145
expectedWords := 58164
expectedBytes := 342190
file := utilities.ReadFile(t, "test.txt")
defer file.Close()
arr, err := utilities.CountAll(file)
if err != nil {
t.Error(err)
}
for i, values := range arr {
if i == 0 && values != expectedLines {
t.Errorf("Expected %d, got %d", expectedLines, values)
}
if i == 1 && values != expectedWords {
t.Errorf("Expected %d, got %d", expectedWords, values)
}
if i == 2 && values != expectedBytes {
t.Errorf("Expected %d, got %d", expectedBytes, values)
}
}
}