-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfileReading_test.go
116 lines (105 loc) · 2.12 KB
/
fileReading_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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// You have to read a file and each row of file contains the number. We have to read a file concurrently and have to append the sum of numbers into the file. If first file contains the filename then also calculate the sum and add with the first file ex.
// file.txt
// 10
// 20
// file2.txt
// 30
// file2.txt
// 10
// output
// file.txt
// 10
// 20
// 30
// 70
// Sum of file.txt is 60 and file2.txt is 10 total 70 should write into file.txt
package main
import (
"os"
"reflect"
"sync"
"testing"
)
func Test_main(t *testing.T) {
tests := []struct {
name string
}{
{name: "Test"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
main()
})
}
}
func Test_readFilePositive(t *testing.T) {
type args struct {
filename string
}
tests := []struct {
name string
args args
wantFile *os.File
}{
{name: "Test readFilePositive", args: args{
filename: "file.txt",
},
wantFile: nil,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if gotFile := readFile(tt.args.filename); reflect.DeepEqual(gotFile, tt.wantFile) {
t.Errorf("readFile() = %v, want %v", gotFile, tt.wantFile)
}
})
}
}
func Test_readFileNegative(t *testing.T) {
type args struct {
filename string
}
tests := []struct {
name string
args args
wantFile *os.File
}{
{name: "Test readFileNegative", args: args{
filename: "file.txt",
},
wantFile: nil,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if gotFile := readFile(tt.args.filename); !reflect.DeepEqual(gotFile, tt.wantFile) {
t.Errorf("readFile() = %v, want %v", gotFile, tt.wantFile)
}
})
}
}
func Test_readTextPositive(t *testing.T) {
file, _ := os.Open("file.txt")
var wg sync.WaitGroup
var mutex sync.Mutex
type args struct {
file *os.File
wg *sync.WaitGroup
mutex *sync.Mutex
}
tests := []struct {
name string
args args
}{
{name: "Test readTextPositive", args: args{
file: file,
wg: &wg,
mutex: &mutex,
}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
readText(tt.args.file, tt.args.wg, tt.args.mutex)
})
}
}