@@ -149,6 +149,9 @@ func TestEdge(t *testing.T) {
149149}
150150
151151func TestLine (t * testing.T ) {
152+ if mess , diff := diff (line (- 1 ), (* Virtual )(nil )); diff {
153+ t .Errorf ("line %s" , mess )
154+ }
152155 if mess , diff := diff (line (0 ).String (), "0 []" ); diff {
153156 t .Errorf ("line %s" , mess )
154157 }
@@ -167,7 +170,73 @@ func TestLine(t *testing.T) {
167170}
168171
169172func TestGeneric (t * testing.T ) {
170- g := Generic (0 , func (v , w int ) bool { return v != 0 })
173+ g := generic0 (- 1 , alwaysEdge )
174+ if mess , diff := diff (g , (* Virtual )(nil )); diff {
175+ t .Errorf ("generic0 %s" , mess )
176+ }
177+ Consistent ("generic0" , t , g )
178+
179+ g = generic0 (0 , alwaysEdge )
180+ if mess , diff := diff (g .String (), "0 []" ); diff {
181+ t .Errorf ("generic0 %s" , mess )
182+ }
183+ Consistent ("generic0" , t , g )
184+
185+ g = generic0 (1 , alwaysEdge )
186+ if mess , diff := diff (g .String (), "1 []" ); diff {
187+ t .Errorf ("generic0 %s" , mess )
188+ }
189+ Consistent ("generic0" , t , g )
190+
191+ g = generic (- 1 , zero , alwaysEdge )
192+ if mess , diff := diff (g , (* Virtual )(nil )); diff {
193+ t .Errorf ("generic %s" , mess )
194+ }
195+ Consistent ("generic" , t , g )
196+
197+ g = generic (0 , zero , alwaysEdge )
198+ if mess , diff := diff (g .String (), "0 []" ); diff {
199+ t .Errorf ("generic %s" , mess )
200+ }
201+ Consistent ("generic" , t , g )
202+
203+ g = generic (1 , zero , alwaysEdge )
204+ if mess , diff := diff (g .String (), "1 []" ); diff {
205+ t .Errorf ("generic %s" , mess )
206+ }
207+ Consistent ("generic" , t , g )
208+
209+ g = generic (2 , zero , alwaysEdge )
210+ if mess , diff := diff (g .String (), "2 [{0 1}]" ); diff {
211+ t .Errorf ("generic %s" , mess )
212+ }
213+ Consistent ("generic" , t , g )
214+
215+ g = Generic (- 1 , nil )
216+ if mess , diff := diff (g , (* Virtual )(nil )); diff {
217+ t .Errorf ("Generic %s" , mess )
218+ }
219+ Consistent ("Generic" , t , g )
220+
221+ g = Generic (0 , nil )
222+ if mess , diff := diff (g .String (), "0 []" ); diff {
223+ t .Errorf ("Generic %s" , mess )
224+ }
225+ Consistent ("Generic" , t , g )
226+
227+ g = Generic (1 , nil )
228+ if mess , diff := diff (g .String (), "1 []" ); diff {
229+ t .Errorf ("Generic %s" , mess )
230+ }
231+ Consistent ("Generic" , t , g )
232+
233+ g = Generic (2 , nil )
234+ if mess , diff := diff (g .String (), "2 [{0 1}]" ); diff {
235+ t .Errorf ("Generic %s" , mess )
236+ }
237+ Consistent ("Generic" , t , g )
238+
239+ g = Generic (0 , func (v , w int ) bool { return v != 0 })
171240 if mess , diff := diff (g .String (), "0 []" ); diff {
172241 t .Errorf ("Generic %s" , mess )
173242 }
@@ -205,9 +274,22 @@ func TestSpecific(t *testing.T) {
205274 t .Errorf ("Specific %s" , mess )
206275 }
207276 Consistent ("Specific" , t , Specific (Kn (4 )))
277+
278+ if mess , diff := diff (res .cost (0 , 0 ), int64 (0 )); diff {
279+ t .Errorf ("Specific cost %s" , mess )
280+ }
281+ if mess , diff := diff (res .cost (0 , 1 ), int64 (1 )); diff {
282+ t .Errorf ("Specific cost %s" , mess )
283+ }
284+ if mess , diff := diff (res .cost (1 , 0 ), int64 (10 )); diff {
285+ t .Errorf ("Specific cost %s" , mess )
286+ }
208287}
209288
210289func TestEmpty (t * testing.T ) {
290+ if mess , diff := diff (Empty (- 1 ), (* Virtual )(nil )); diff {
291+ t .Errorf ("Empty %s" , mess )
292+ }
211293 if mess , diff := diff (Empty (0 ).String (), "0 []" ); diff {
212294 t .Errorf ("Empty %s" , mess )
213295 }
@@ -223,6 +305,9 @@ func TestEmpty(t *testing.T) {
223305}
224306
225307func TestKn (t * testing.T ) {
308+ if mess , diff := diff (Kn (- 1 ), (* Virtual )(nil )); diff {
309+ t .Errorf ("Kn %s" , mess )
310+ }
226311 if mess , diff := diff (Kn (0 ).String (), "0 []" ); diff {
227312 t .Errorf ("Kn %s" , mess )
228313 }
@@ -289,6 +374,12 @@ func TestKeep(t *testing.T) {
289374 t .Errorf ("Keep %s" , mess )
290375 }
291376 Consistent ("Keep" , t , g )
377+
378+ g = Cycle (3 ).AddCost (1 ).Keep (nil )
379+ if mess , diff := diff (g .String (), "3 [{0 1}:1 {0 2}:1 {1 2}:1]" ); diff {
380+ t .Errorf ("Keep %s" , mess )
381+ }
382+ Consistent ("Keep" , t , g )
292383}
293384
294385func TestAddCost (t * testing.T ) {
@@ -315,10 +406,58 @@ func TestAddCostFunc(t *testing.T) {
315406 }
316407 Consistent ("AccCostFunc" , t , res )
317408
409+ if mess , diff := diff (res .Cost (0 , 0 ), int64 (0 )); diff {
410+ t .Errorf ("Cost %s" , mess )
411+ }
412+ if mess , diff := diff (res .Cost (0 , 1 ), int64 (5 )); diff {
413+ t .Errorf ("Cost %s" , mess )
414+ }
415+ if mess , diff := diff (res .Cost (- 1 , 0 ), int64 (0 )); diff {
416+ t .Errorf ("Cost %s" , mess )
417+ }
418+
419+ res = Grid (1 , 2 ).AddCostFunc (nil )
420+ exp = "2 [{0 1}]"
421+ if mess , diff := diff (res .String (), exp ); diff {
422+ t .Errorf ("AddCostFunc %s" , mess )
423+ }
424+ Consistent ("AccCostFunc" , t , res )
425+
318426 res = Empty (0 ).AddCostFunc (Cost (5 ))
319427 exp = "0 []"
320428 if mess , diff := diff (res .String (), exp ); diff {
321429 t .Errorf ("AddCostFunc %s" , mess )
322430 }
323431 Consistent ("AddCostFunc" , t , res )
324432}
433+
434+ func TestVisit (t * testing.T ) {
435+ g := Grid (1 , 2 ).AddCost (5 )
436+ res := g .Visit (0 , func (w int , c int64 ) (skip bool ) {
437+ return w == 1 && c == 5
438+ })
439+ if mess , diff := diff (res , true ); diff {
440+ t .Errorf ("Visit %s" , mess )
441+ }
442+
443+ res = g .VisitFrom (0 , 0 , func (w int , c int64 ) (skip bool ) {
444+ return w == 1 && c == 5
445+ })
446+ if mess , diff := diff (res , true ); diff {
447+ t .Errorf ("Visit %s" , mess )
448+ }
449+
450+ res = g .VisitFrom (0 , - 1 , func (w int , c int64 ) (skip bool ) {
451+ return w == 1 && c == 5
452+ })
453+ if mess , diff := diff (res , true ); diff {
454+ t .Errorf ("Visit %s" , mess )
455+ }
456+
457+ res = g .VisitFrom (0 , 2 , func (w int , c int64 ) (skip bool ) {
458+ return w == 1 && c == 5
459+ })
460+ if mess , diff := diff (res , false ); diff {
461+ t .Errorf ("Visit %s" , mess )
462+ }
463+ }
0 commit comments