public void TwoVertexGraphWithCycelsTest() { var graph = new AdjacencyListGraph(2); graph.AddArrow(0, 1); graph.AddArrow(1, 0); // var expectedResult = new[] {new[] {1, 0}}; var result = searcher.FindCycles(graph); Assert.That(result.Count, Is.EqualTo(0)); // Assert.That(CompareResult(expectedResult, result)); }
public void ThreeVertexGraphWithCycleBetweenSecondAndThirdTest() { var graph = new AdjacencyListGraph(3); graph.AddArrow(0, 1); graph.AddArrow(1, 2); graph.AddArrow(2, 1); // var expectedResult = new[] {new[] {1, 2}}; var result = searcher.FindCycles(graph); Assert.That(result.Count, Is.EqualTo(0)); // Assert.That(CompareResult(expectedResult, result)); }
public void TestClusteringCoefficientForVertexInGraphWithAloneVertex() { var graph = new AdjacencyListGraph(4); graph.AddArrow(0, 3); graph.AddArrow(0, 1); graph.AddArrow(1, 2); graph.AddArrow(2, 0); ClusteringCoefficient cCoefficient = new ClusteringCoefficient(graph); var result = cCoefficient.GetClusteringCoefficientForVertex(3); double expectedResult = 0d; Assert.That(result, Is.EqualTo(expectedResult)); }
public void TestClusteringCoefficientForGraphInGraphWithAloneVertex() { var graph = new AdjacencyListGraph(4); graph.AddArrow(0, 3); graph.AddArrow(0, 1); graph.AddArrow(1, 2); graph.AddArrow(2, 0); ClusteringCoefficient cCoefficient = new ClusteringCoefficient(graph); var result = cCoefficient.GetClusteringCoefficientForGraph(); double expectedResult = Math.Round((Math.Round(1d / 3d, 3) + 1 + 1 + 0) / 4d, 4); Assert.That(result, Is.EqualTo(expectedResult)); }
public void OnePathAndOneSegmentTest() { var graph = new AdjacencyListGraph(4); graph.AddArrow(0, 1); graph.AddArrow(1, 2); graph.AddArrow(2, 3); graph.AddArrow(3, 0); graph.AddArrow(3, 2); var result = searcher.FindCycles(graph); Assert.That(result.Count, Is.EqualTo(1)); Assert.That(result[0], Is.EquivalentTo(new[] { 3, 2, 1, 0 })); //Assert.That(result[1], Is.EquivalentTo(new[] { 3, 2 })); }
public void TestReciprocalPoints() { var graph = new AdjacencyListGraph(2); graph.AddArrow(0, 1) .AddArrow(1, 0); Assert.That(graph.AreReciprocal(0, 1)); }
public void TestVerticeCanPointToMultipleVertices() { var graph = new AdjacencyListGraph(3); graph.AddArrow(0, 1) .AddArrow(0, 2); Assert.That(graph.VerticesCount == 3); Assert.That(graph.HasArrow(0, 1)); Assert.That(graph.HasArrow(0, 2)); }
public void MediumGraphWithThreeCyclesTest() { var graph = new AdjacencyListGraph(5); graph.AddArrow(0, 4); graph.AddArrow(4, 3); graph.AddArrow(3, 1); graph.AddArrow(3, 2); graph.AddArrow(1, 0); graph.AddArrow(1, 2); graph.AddArrow(2, 1); var result = searcher.FindCycles(graph); Assert.That(result.Count, Is.EqualTo(2)); // Assert.That(result[0], Is.EquivalentTo(new[] {0, 4, 3, 1})); // Assert.That(result[1], Is.EquivalentTo(new[] {2, 1})); // Assert.That(result[1], Is.EquivalentTo(new[] {0, 4, 3, 2, 1})); }
public void ExtensionTest() { var graph = new AdjacencyListGraph(8); graph.AddArrow(0, 1); graph.AddArrow(1, 2); graph.AddArrow(2, 0); graph.AddArrow(3, 1); graph.AddArrow(3, 2); graph.AddArrow(5, 2); graph.AddArrow(4, 3); graph.AddArrow(3, 4); graph.AddArrow(4, 5); graph.AddArrow(6, 5); graph.AddArrow(5, 6); graph.AddArrow(7, 4); var result = graph.FindCycles(); Assert.That(result.Count, Is.EqualTo(1)); //CollectionAssert.AreEqual(new[] { 0, 1, 2 }, result[0]); //CollectionAssert.AreEqual(new[] { 3, 4 }, result[1]); //CollectionAssert.AreEqual(new[] { 5, 6 }, result[2]); }
public void VeryHardGraphWithFifteenCyclesTest() { var graph = new AdjacencyListGraph(15); graph.AddArrow(8, 4); graph.AddArrow(3, 4); graph.AddArrow(5, 10); graph.AddArrow(0, 1); graph.AddArrow(11, 9); graph.AddArrow(9, 11); graph.AddArrow(14, 7); graph.AddArrow(1, 3); graph.AddArrow(10, 6); graph.AddArrow(11, 5); graph.AddArrow(5, 11); graph.AddArrow(8, 13); graph.AddArrow(13, 8); graph.AddArrow(4, 2); graph.AddArrow(2, 0); graph.AddArrow(9, 12); graph.AddArrow(12, 9); graph.AddArrow(12, 8); graph.AddArrow(8, 12); graph.AddArrow(7, 13); graph.AddArrow(1, 6); graph.AddArrow(6, 14); graph.AddArrow(0, 5); graph.AddArrow(9, 2); graph.AddArrow(7, 3); var result = searcher.FindCycles(graph); Assert.That(result.Count, Is.EqualTo(10)); }
public void HardGraphWithEightCyclesTest() { var graph = new AdjacencyListGraph(13); graph.AddArrow(0, 1); graph.AddArrow(0, 5); graph.AddArrow(5, 4); graph.AddArrow(4, 2); graph.AddArrow(2, 0); graph.AddArrow(2, 3); graph.AddArrow(3, 2); graph.AddArrow(3, 5); graph.AddArrow(4, 3); graph.AddArrow(4, 11); graph.AddArrow(11, 12); graph.AddArrow(12, 9); graph.AddArrow(9, 10); graph.AddArrow(10, 12); graph.AddArrow(9, 11); graph.AddArrow(0, 6); graph.AddArrow(6, 9); graph.AddArrow(7, 6); graph.AddArrow(7, 8); graph.AddArrow(8, 7); var result = searcher.FindCycles(graph); Assert.That(result.Count, Is.EqualTo(6)); // Assert.That(result[0], Is.EquivalentTo(new[] { 0, 5, 4, 2 })); // Assert.That(result[1], Is.EquivalentTo(new[] { 2, 3 })); // Assert.That(result[1], Is.EquivalentTo(new[] { 5, 4, 2, 3 })); // Assert.That(result[2], Is.EquivalentTo(new[] { 0, 5, 4, 3, 2 })); // Assert.That(result[3], Is.EquivalentTo(new[] { 5, 4, 3 })); // Assert.That(result[4], Is.EquivalentTo(new[] { 12, 9, 10 })); // Assert.That(result[5], Is.EquivalentTo(new[] { 11, 12, 9 })); // Assert.That(result[7], Is.EquivalentTo(new[] { 7, 8 })); }