(t *testing.T)
| 323 | } |
| 324 | |
| 325 | func TestTarjan(t *testing.T) { |
| 326 | for i, test := range graphTests { |
| 327 | var g graph |
| 328 | if test.path != nil { |
| 329 | g = graphFrom(test.path) |
| 330 | } else { |
| 331 | g = test.g |
| 332 | } |
| 333 | tar := newTarjan(g) |
| 334 | gotSCCs := tar.sccs |
| 335 | if test.orderIsAmbiguous { |
| 336 | // We lose topological order here, but that |
| 337 | // is not important for this use case. |
| 338 | sort.Sort(byComponentLengthOrStart(test.wantSCCs)) |
| 339 | sort.Sort(byComponentLengthOrStart(gotSCCs)) |
| 340 | } |
| 341 | // tarjan.strongconnect does range iteration over maps, |
| 342 | // so sort SCC members to ensure consistent ordering. |
| 343 | for _, scc := range gotSCCs { |
| 344 | sort.Ints(scc) |
| 345 | } |
| 346 | if !reflect.DeepEqual(gotSCCs, test.wantSCCs) { |
| 347 | t.Errorf("unexpected tarjan scc result for %d:\n\tgot:%v\n\twant:%v", i, gotSCCs, test.wantSCCs) |
| 348 | } |
| 349 | gotAdj := tar.sccSubGraph(2) |
| 350 | if !reflect.DeepEqual(gotAdj, test.wantAdj) { |
| 351 | t.Errorf("unexpected tarjan sccSubGraph(2) result for %d:\n\tgot:%#v\n\twant:%#v", i, gotAdj, test.wantAdj) |
| 352 | } |
| 353 | } |
| 354 | } |
| 355 | |
| 356 | func TestJohnson(t *testing.T) { |
| 357 | for i, test := range graphTests { |
nothing calls this directly
no test coverage detected
searching dependent graphs…