1 package progress
2
3 import (
4 "fmt"
5 "strings"
6 "testing"
7 "time"
8
9 "github.com/stretchr/testify/assert"
10 )
11
12 func TestIndeterminateIndicatorDominoes(t *testing.T) {
13 maxLen := 10
14 expectedTexts := []string{
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 out := strings.Builder{}
48 f := IndeterminateIndicatorDominoes(time.Millisecond * 10)
49 for idx, expectedText := range expectedTexts {
50 actual := f(maxLen)
51 assert.Equal(t, 0, actual.Position, fmt.Sprintf("expectedTexts[%d]", idx))
52 assert.Equal(t, expectedText, actual.Text, fmt.Sprintf("expectedTexts[%d]", idx))
53 out.WriteString(fmt.Sprintf("`%v`,\n", actual.Text))
54 time.Sleep(time.Millisecond * 10)
55 }
56 if t.Failed() {
57 fmt.Println(out.String())
58 }
59 }
60
61 func TestIndeterminateIndicatorMovingBackAndForth(t *testing.T) {
62 maxLen := 10
63 indicator := "<=>"
64 expectedPositions := []int{
65 0, 1, 2, 3, 4, 5, 6, 7, 6, 5, 4, 3, 2, 1,
66 0, 1, 2, 3, 4, 5, 6, 7, 6, 5, 4, 3, 2, 1,
67 }
68
69 f := IndeterminateIndicatorMovingBackAndForth(indicator, time.Millisecond*10)
70 for idx, expectedPosition := range expectedPositions {
71 actual := f(maxLen)
72 assert.Equal(t, expectedPosition, actual.Position, fmt.Sprintf("expectedPositions[%d]", idx))
73 time.Sleep(time.Millisecond * 10)
74 }
75 }
76
77 func Test_indeterminateIndicatorMovingBackAndForth1(t *testing.T) {
78 maxLen := 10
79 indicator := "?"
80 expectedPositions := []int{
81 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 2, 1,
82 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 2, 1,
83 }
84
85 f := indeterminateIndicatorMovingBackAndForth(indicator)
86 for idx, expectedPosition := range expectedPositions {
87 actual := f(maxLen)
88 assert.Equal(t, expectedPosition, actual.Position, fmt.Sprintf("expectedPositions[%d]", idx))
89 }
90 }
91
92 func Test_indeterminateIndicatorMovingBackAndForth2(t *testing.T) {
93 maxLen := 10
94 indicator := "<>"
95 expectedPositions := []int{
96 0, 1, 2, 3, 4, 5, 6, 7, 8, 7, 6, 5, 4, 3, 2, 1,
97 0, 1, 2, 3, 4, 5, 6, 7, 8, 7, 6, 5, 4, 3, 2, 1,
98 }
99
100 f := indeterminateIndicatorMovingBackAndForth(indicator)
101 for idx, expectedPosition := range expectedPositions {
102 actual := f(maxLen)
103 assert.Equal(t, expectedPosition, actual.Position, fmt.Sprintf("expectedPositions[%d]", idx))
104 }
105 }
106
107 func Test_indeterminateIndicatorMovingBackAndForth3(t *testing.T) {
108 maxLen := 10
109 indicator := "<=>"
110 expectedPositions := []int{
111 0, 1, 2, 3, 4, 5, 6, 7, 6, 5, 4, 3, 2, 1,
112 0, 1, 2, 3, 4, 5, 6, 7, 6, 5, 4, 3, 2, 1,
113 }
114
115 f := indeterminateIndicatorMovingBackAndForth(indicator)
116 for idx, expectedPosition := range expectedPositions {
117 actual := f(maxLen)
118 assert.Equal(t, expectedPosition, actual.Position, fmt.Sprintf("expectedPositions[%d]", idx))
119 }
120 }
121
122 func TestIndeterminateIndicatorMovingLeftToRight(t *testing.T) {
123 maxLen := 10
124 indicator := "?"
125 expectedPositions := []int{
126 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
127 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
128 }
129
130 f := IndeterminateIndicatorMovingLeftToRight(indicator, time.Millisecond*10)
131 for idx, expectedPosition := range expectedPositions {
132 actual := f(maxLen)
133 assert.Equal(t, expectedPosition, actual.Position, fmt.Sprintf("expectedPositions[%d]", idx))
134 time.Sleep(time.Millisecond * 10)
135 }
136 }
137
138 func Test_indeterminateIndicatorMovingLeftToRight1(t *testing.T) {
139 maxLen := 10
140 indicator := "?"
141 expectedPositions := []int{
142 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
143 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
144 }
145
146 f := indeterminateIndicatorMovingLeftToRight(indicator)
147 for idx, expectedPosition := range expectedPositions {
148 actual := f(maxLen)
149 assert.Equal(t, expectedPosition, actual.Position, fmt.Sprintf("expectedPositions[%d]", idx))
150 }
151 }
152
153 func Test_indeterminateIndicatorMovingLeftToRight2(t *testing.T) {
154 maxLen := 10
155 indicator := "<>"
156 expectedPositions := []int{
157 0, 1, 2, 3, 4, 5, 6, 7, 8,
158 0, 1, 2, 3, 4, 5, 6, 7, 8,
159 }
160
161 f := indeterminateIndicatorMovingLeftToRight(indicator)
162 for idx, expectedPosition := range expectedPositions {
163 actual := f(maxLen)
164 assert.Equal(t, expectedPosition, actual.Position, fmt.Sprintf("expectedPositions[%d]", idx))
165 }
166 }
167
168 func Test_indeterminateIndicatorMovingLeftToRight3(t *testing.T) {
169 maxLen := 10
170 indicator := "<=>"
171 expectedPositions := []int{
172 0, 1, 2, 3, 4, 5, 6, 7,
173 0, 1, 2, 3, 4, 5, 6, 7,
174 }
175
176 f := indeterminateIndicatorMovingLeftToRight(indicator)
177 for idx, expectedPosition := range expectedPositions {
178 actual := f(maxLen)
179 assert.Equal(t, expectedPosition, actual.Position, fmt.Sprintf("expectedPositions[%d]", idx))
180 }
181 }
182
183 func TestIndeterminateIndicatorMovingRightToLeft(t *testing.T) {
184 maxLen := 10
185 indicator := "?"
186 expectedPositions := []int{
187 9, 8, 7, 6, 5, 4, 3, 2, 1, 0,
188 9, 8, 7, 6, 5, 4, 3, 2, 1, 0,
189 }
190
191 f := IndeterminateIndicatorMovingRightToLeft(indicator, time.Millisecond*10)
192 for idx, expectedPosition := range expectedPositions {
193 actual := f(maxLen)
194 assert.Equal(t, expectedPosition, actual.Position, fmt.Sprintf("expectedPositions[%d]", idx))
195 time.Sleep(time.Millisecond * 10)
196 }
197 }
198
199 func Test_indeterminateIndicatorMovingRightToLeft1(t *testing.T) {
200 maxLen := 10
201 indicator := "?"
202 expectedPositions := []int{
203 9, 8, 7, 6, 5, 4, 3, 2, 1, 0,
204 9, 8, 7, 6, 5, 4, 3, 2, 1, 0,
205 }
206
207 f := indeterminateIndicatorMovingRightToLeft(indicator)
208 for idx, expectedPosition := range expectedPositions {
209 actual := f(maxLen)
210 assert.Equal(t, expectedPosition, actual.Position, fmt.Sprintf("expectedPositions[%d]", idx))
211 }
212 }
213
214 func Test_indeterminateIndicatorMovingRightToLeft2(t *testing.T) {
215 maxLen := 10
216 indicator := "<>"
217 expectedPositions := []int{
218 8, 7, 6, 5, 4, 3, 2, 1, 0,
219 8, 7, 6, 5, 4, 3, 2, 1, 0,
220 }
221
222 f := indeterminateIndicatorMovingRightToLeft(indicator)
223 for idx, expectedPosition := range expectedPositions {
224 actual := f(maxLen)
225 assert.Equal(t, expectedPosition, actual.Position, fmt.Sprintf("expectedPositions[%d]", idx))
226 }
227 }
228
229 func Test_indeterminateIndicatorMovingRightToLeft3(t *testing.T) {
230 maxLen := 10
231 indicator := "<=>"
232 expectedPositions := []int{
233 7, 6, 5, 4, 3, 2, 1, 0,
234 7, 6, 5, 4, 3, 2, 1, 0,
235 }
236
237 f := indeterminateIndicatorMovingRightToLeft(indicator)
238 for idx, expectedPosition := range expectedPositions {
239 actual := f(maxLen)
240 assert.Equal(t, expectedPosition, actual.Position, fmt.Sprintf("expectedPositions[%d]", idx))
241 }
242 }
243
244 func TestIndeterminateIndicatorPacMan(t *testing.T) {
245 maxLen := 10
246 expectedTexts := []string{
247 "ᗧ ",
248 " ᗧ ",
249 " ᗧ ",
250 " ᗧ ",
251 " ᗧ ",
252 " ᗧ ",
253 " ᗧ ",
254 " ᗧ ",
255 " ᗧ ",
256 " ᗧ",
257 " ᗤ ",
258 " ᗤ ",
259 " ᗤ ",
260 " ᗤ ",
261 " ᗤ ",
262 " ᗤ ",
263 " ᗤ ",
264 " ᗤ ",
265 "ᗤ ",
266 " ᗧ ",
267 " ᗧ ",
268 " ᗧ ",
269 " ᗧ ",
270 " ᗧ ",
271 " ᗧ ",
272 " ᗧ ",
273 " ᗧ ",
274 " ᗧ",
275 }
276
277 out := strings.Builder{}
278 f := IndeterminateIndicatorPacMan(time.Millisecond * 10)
279 for idx, expectedText := range expectedTexts {
280 actual := f(maxLen)
281 assert.Equal(t, expectedText, actual.Text, fmt.Sprintf("expectedTexts[%d]", idx))
282 out.WriteString(fmt.Sprintf("%#v,\n", actual.Text))
283 time.Sleep(time.Millisecond * 10)
284 }
285 if t.Failed() {
286 fmt.Println(out.String())
287 }
288 }
289
View as plain text