generated from Gophing-Around/hashcode-golang-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ioutil_test.go
43 lines (37 loc) · 1014 Bytes
/
ioutil_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
package main
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestReadInput(t *testing.T) {
t.Run("Read input and take only the first word of each line", func(t *testing.T) {
result := make([]string, 0)
handleWordsOnLine := func(lineReady <-chan bool, wordChannel <-chan string, readNextLine chan<- bool, doneChannel chan<- bool) {
for range lineReady {
readLine := true
isFirstWord := true
for readLine {
select {
case word := <-wordChannel:
if isFirstWord {
result = append(result, word)
isFirstWord = false
}
default:
readLine = false
}
}
readNextLine <- true
}
doneChannel <- true
}
ReadInput("mock/file_mock.txt", 8, 10, handleWordsOnLine)
require.Len(t, result, 6)
require.Equal(t, `0-0`, result[0])
require.Equal(t, `1-0`, result[1])
require.Equal(t, `2-0`, result[2])
require.Equal(t, `3-0`, result[3])
require.Equal(t, `4-0`, result[4])
require.Equal(t, `5-0`, result[5])
})
}