public void TestAPI() { var root = new IntWeightedNode(42); Assert.AreEqual(42, root.Content); Assert.AreEqual(0, root.NeighborsCount); Assert.IsNull(root.Find(42)); Assert.IsFalse(root.HasNeighbor(root)); var neighbor = new IntWeightedNode(21); root.AddDirectedEdge(neighbor, 100); Assert.AreEqual(1, root.NeighborsCount); Assert.AreEqual(100, root.Cost(neighbor)); Assert.IsTrue(root.HasNeighbor(neighbor)); var found = root.Find(21); Assert.AreSame(found, neighbor); var neighborsAndWeights = ">"; root.ForEachNeighborAndCost(pair => { neighborsAndWeights += $" {(pair.Key as IntWeightedNode).Content.ToString()}" + $":{pair.Value.ToString()}"; }); Assert.AreEqual("> 21:100", neighborsAndWeights); var neighbors = ">"; root.ForEachNeighbor((node) => { neighbors += $" {(node as IntWeightedNode).Content.ToString()}"; }); Assert.AreEqual("> 21", neighbors); root.RemoveDirectedEdge(neighbor); Assert.AreEqual(0, root.NeighborsCount); Assert.IsFalse(root.HasNeighbor(neighbor)); Assert.IsNull(root.Find(21)); }
public void TestEdgesWeight() { var count = 10; var root = new IntWeightedNode(0); for (int cost = 100; cost < 100 + count; cost++) { var neighbor = new IntWeightedNode(cost); // Store cost in node root.AddDirectedEdge(neighbor, cost); } // The cost of each edge to neighbor was stored a the value of the IntWeightedNode, so they must match root.ForEachNeighborAndCost(pair => { var intNode = pair.Key as IntWeightedNode; var cost = pair.Value; Assert.AreEqual(intNode.Content, cost); }); }