-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse-conc_test.go
127 lines (111 loc) · 3.52 KB
/
parse-conc_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
117
118
119
120
121
122
123
124
125
126
127
package main
import (
"testing"
"reflect"
"strings"
"bufio"
)
//func Init() {
// phrases = append(phrases, M{})
//}
func TestPhraseToStr(t *testing.T) {
var phr [3][]rune
r1 := []rune("aaa")
r2 := []rune("bbb")
r3 := []rune("ccc")
phr[0] = r1
phr[1] = r2
phr[2] = r3
expected := "aaa bbb ccc"
actual := phraseToStr(phr)
if actual != expected {
t.Errorf("expected: %v \nactual = %v \n", actual, expected)
}
}
func TestMergeMaps(t *testing.T) {
map1 := map[string]int{"aaa": 2, "bbb": 2," ccc": 1, "ggg": 7}
map2 := map[string]int{"aaa": 3, "bbb": 1," ccc": 1, "zzz": 9, "yyy": 3}
map3 := map[string]int{"ddd": 2, "eee": 2," fff": 1}
maps := []M{map1, map2, map3}
expected := map[string]int{"aaa": 5, "bbb": 3, "ccc": 2, "ddd": 2, "eee": 2, "fff": 1, "ggg": 7, "yyy": 3, "zzz": 9}
actual := mergeMaps(maps)
eq := reflect.DeepEqual(actual, expected)
if eq {
t.Errorf("Expected result of merging maps:\n %v is:\n%v\nactual:\n%v", maps, expected, actual)
}
}
func TestProcessInput1(t *testing.T) {
// type M map[string]int
// var phrases []M
phrases = append(phrases, M{})
s := "aa'a bbb, ccc : ddd"
sr := strings.NewReader(s)
br := bufio.NewReader(sr)
expected := map[string]int{"a'aa bbb ccc": 1, "bbb ccc ddd": 1}
processInput(*br, 0)
actual := phrases[0]
eq := reflect.DeepEqual(actual, expected)
if eq {
t.Errorf("expected: %v \nactual = %v \n", expected, actual)
}
}
func TestProcessInput2(t *testing.T) {
// type M map[string]int
// var phrases []M
phrases = append(phrases, M{})
s := "aaa bbb ccc ddd aaa bbb ccc ddd"
sr := strings.NewReader(s)
br := bufio.NewReaderSize(sr, 64)
expected := map[string]int{"aaa bbb ccc ddd": 2, "bbb ccc ddd": 2, "ccc ddd aaa": 1, "ddd aaa bbb": 1}
processInput(*br, 1)
actual := phrases[1]
eq := reflect.DeepEqual(actual, expected)
if eq {
t.Errorf("expected: %v \nactual = %v \n", expected, actual)
}
}
func TestProcessInput3(t *testing.T) {
// type M map[string]int
// var phrases []M
phrases = append(phrases, M{})
s := "aaa bbb"
sr := strings.NewReader(s)
br := bufio.NewReaderSize(sr, 19)
expected := map[string]int{}
processInput(*br, 2)
actual := phrases[2]
eq := reflect.DeepEqual(actual, expected)
if eq {
t.Errorf("expected: %v \nactual = %v \n", actual, expected)
}
}
func TestProcessInput4(t *testing.T) {
// type M map[string]int
// var phrases []M
phrases = append(phrases, M{})
s := ",aaa - bbb ;ccc"
sr := strings.NewReader(s)
br := bufio.NewReaderSize(sr, 19)
expected := map[string]int{"aaa bbb ccc" : 1}
processInput(*br, 3)
actual := phrases[3]
eq := reflect.DeepEqual(actual, expected)
if eq {
t.Errorf("expected: %v \nactual = %v \n", actual, expected)
}
}
func TestProcessInputUnicode(t *testing.T) {
// type M map[string]int
// var phrases []M
phrases = append(phrases, M{})
s := "อยาลางผลาญฤๅเขนฆาบฑาใคร ไมถอโทษโกรธแชงซดฮดฮดดา หดอภยเหมอนกฬาอชฌาสย"
sr := strings.NewReader(s)
br := bufio.NewReaderSize(sr, 19)
expected := map[string]int{"อยาลางผลาญฤๅเขนฆาบฑาใคร ไมถอโทษโกรธแชงซดฮดฮดดา หดอภยเหมอนกฬาอชฌาสย" : 1}
processInput(*br, 4)
actual := phrases[4]
eq := reflect.DeepEqual(actual, expected)
if eq {
t.Errorf("expected: %v \nactual = %v \n", actual, expected)
}
}