Ejemplo n.º 1
0
func TestUndirectedDenseAddRemove(t *testing.T) {
	dg := concrete.NewUndirectedDenseGraph(10, false, math.Inf(1))
	dg.SetEdgeWeight(concrete.Edge{concrete.Node(0), concrete.Node(2)}, 1)

	if neighbors := dg.From(concrete.Node(0)); len(neighbors) != 1 || neighbors[0].ID() != 2 ||
		dg.EdgeBetween(concrete.Node(0), concrete.Node(2)) == nil {
		t.Errorf("Couldn't add neighbor")
	}

	if neighbors := dg.From(concrete.Node(2)); len(neighbors) != 1 || neighbors[0].ID() != 0 ||
		dg.EdgeBetween(concrete.Node(2), concrete.Node(0)) == nil {
		t.Errorf("Adding an undirected neighbor didn't add it reciprocally")
	}
}
Ejemplo n.º 2
0
func TestBasicDensePassable(t *testing.T) {
	dg := concrete.NewUndirectedDenseGraph(5, true, math.Inf(1))
	if dg == nil {
		t.Fatal("Directed graph could not be made")
	}

	for i := 0; i < 5; i++ {
		if !dg.Has(concrete.Node(i)) {
			t.Errorf("Node that should exist doesn't: %d", i)
		}

		if degree := dg.Degree(concrete.Node(i)); degree != 4 {
			t.Errorf("Node in passable graph missing neighbors. Node: %d Degree: %d", i, degree)
		}
	}

	for i := 5; i < 10; i++ {
		if dg.Has(concrete.Node(i)) {
			t.Errorf("Node exists that shouldn't: %d", i)
		}
	}
}