예제 #1
0
        public void AddEdge_SecondOutEdge_SourceHasOutDegreeTwo()
        {
            var graph = new DirectedGraphWithoutInEdges <int, int>();
            var v1    = graph.AddVertex(0);
            var v2    = graph.AddVertex(0);

            graph.AddEdge(v1, v2, 0);
            graph.AddEdge(v1, v2, 0);
            Assert.That(graph.GetOutDegree(v1), Is.EqualTo(2));
        }
예제 #2
0
        public void RemoveEdge_SecondEdge_OutDegreeIsOne()
        {
            var graph = new DirectedGraphWithoutInEdges <int, int>();
            var v1    = graph.AddVertex(0);
            var v2    = graph.AddVertex(0);

            graph.AddEdge(v1, v2, 0);
            var e = graph.AddEdge(v1, v2, 0);

            graph.RemoveEdge(e);
            Assert.That(graph.GetOutDegree(v1), Is.EqualTo(1));
        }
예제 #3
0
        public void RemoveVertex_VertexHasSelfEdge_Throws()
        {
            var graph = new DirectedGraphWithoutInEdges <int, int>();
            var v     = graph.AddVertex(0);

            graph.AddEdge(v, v, 0);
            Assert.That(() => graph.RemoveVertex(v), Throws.ArgumentException);
        }
예제 #4
0
        public void AddEdge_GraphWithTwoVertices_GetEdgeTagReturnsData()
        {
            var graph = new DirectedGraphWithoutInEdges <int, int>();
            var v1    = graph.AddVertex(0);
            var v2    = graph.AddVertex(0);
            var e     = graph.AddEdge(v1, v2, 42);

            Assert.That(graph.GetEdgeTag(e), Is.EqualTo(42));
        }
예제 #5
0
        public void AddEdge_GraphWithTwoVertices_EdgeCountIsOne()
        {
            var graph = new DirectedGraphWithoutInEdges <int, int>();
            var v1    = graph.AddVertex(0);
            var v2    = graph.AddVertex(0);

            graph.AddEdge(v1, v2, 0);
            Assert.That(graph.EdgeCount, Is.EqualTo(1));
        }
예제 #6
0
        public void GetEdge_GraphWithEdge_DataIsCorrect()
        {
            var graph = new DirectedGraphWithoutInEdges <int, int>();
            var v0    = graph.AddVertex(0);
            var v1    = graph.AddVertex(0);
            var e     = graph.AddEdge(v0, v1, 42);

            Assert.That(graph.GetEdgeTag(e), Is.EqualTo(42));
        }
예제 #7
0
        public void RemoveEdge_SelfEdge_EdgeCountIsZero()
        {
            var graph = new DirectedGraphWithoutInEdges <int, int>();
            var v     = graph.AddVertex(0);
            var e     = graph.AddEdge(v, v, 0);

            graph.RemoveEdge(e);
            Assert.That(graph.EdgeCount, Is.Zero);
        }
예제 #8
0
        public void GetEdge_GraphWithEdge_SourceAndTargetAreCorrect()
        {
            var graph = new DirectedGraphWithoutInEdges <int, int>();
            var v0    = graph.AddVertex(0);
            var v1    = graph.AddVertex(0);
            var e     = graph.AddEdge(v0, v1, 0);

            Assert.That(graph.GetSource(e), Is.EqualTo(v0));
            Assert.That(graph.GetTarget(e), Is.EqualTo(v1));
        }
예제 #9
0
        public void AddEdge_GraphWithTwoVertices_SourceHasOutEdge()
        {
            var graph = new DirectedGraphWithoutInEdges <int, int>();
            var v1    = graph.AddVertex(0);
            var v2    = graph.AddVertex(0);

            graph.AddEdge(v1, v2, 0);
            Assert.That(graph.GetOutDegree(v1), Is.EqualTo(1));
            var outEdges = graph.GetOutEdges(v1);

            Assert.That(outEdges.Length, Is.EqualTo(1));
            Assert.That(graph.GetSource(outEdges[0]), Is.EqualTo(v1));
            Assert.That(graph.GetTarget(outEdges[0]), Is.EqualTo(v2));
        }