Beispiel #1
0
        public void AddEdge_Works()
        {
            var v1 = new TestVertex(1, "v1");
            var v2 = new TestVertex(2, "v2");
            var e1 = new TestEdge(3, 1, 2, "e1");

            var graph = TestGraph.Empty()
                        .AddVertex(v1)
                        .AddVertex(v2)
                        .AddEdge(e1);

            graph.Vertices.Should().BeEquivalentTo(v1, v2);
            graph.Edges.Should().BeEquivalentTo(e1);
        }
Beispiel #2
0
        public void UpdateEdge_Name_Works()
        {
            var v1 = new TestVertex(1, "v1");
            var v2 = new TestVertex(2, "v2");
            var e1 = new TestEdge(1, 1, 2, "e1");

            var graph = TestGraph.Empty()
                        .AddVertex(v1)
                        .AddVertex(v2)
                        .AddEdge(e1)
                        .UpdateEdge(e1.WithName("e2"));

            graph.Vertices.Should().BeEquivalentTo(v1, v2);
            graph.Edges.Should().BeEquivalentTo(new TestEdge(1, 1, 2, "e2"));
        }
Beispiel #3
0
        public void PathExists_Works()
        {
            var v1 = new TestVertex(1, "v1");
            var v2 = new TestVertex(2, "v2");
            var v3 = new TestVertex(3, "v3");
            var e1 = new TestEdge(1, 1, 2, "e1");
            var e2 = new TestEdge(2, 2, 3, "e2");

            var graph = TestGraph.Empty()
                        .AddVertex(v1)
                        .AddVertex(v2)
                        .AddVertex(v3)
                        .AddEdge(e1)
                        .AddEdge(e2);

            graph.PathExists(1, 2).Should().BeTrue();
            graph.PathExists(1, 3).Should().BeTrue();
            graph.PathExists(1, 1).Should().BeFalse();
            graph.PathExists(2, 1).Should().BeFalse();
        }
Beispiel #4
0
        public void GetAdjacentVertices_Works()
        {
            var v1 = new TestVertex(1, "v1");
            var v2 = new TestVertex(2, "v2");
            var v3 = new TestVertex(3, "v3");
            var e1 = new TestEdge(1, 1, 2, "e1");
            var e2 = new TestEdge(2, 2, 3, "e2");

            var graph = TestGraph.Empty()
                        .AddVertex(v1)
                        .AddVertex(v2)
                        .AddVertex(v3)
                        .AddEdge(e1)
                        .AddEdge(e2);

            graph.GetAdjacentVertices(1, EdgeDirection.Out).Should().BeEquivalentTo(v2);
            graph.GetAdjacentVertices(1, EdgeDirection.In).Should().BeEmpty();
            graph.GetAdjacentVertices(3, EdgeDirection.In).Should().BeEquivalentTo(v2);
            graph.GetAdjacentVertices(1, EdgeDirection.Out, recursive: true).Should().BeEquivalentTo(v2, v3);
            graph.GetAdjacentVertices(3, EdgeDirection.In, recursive: true).Should().BeEquivalentTo(v1, v2);
            graph.GetAdjacentVertices(1, EdgeDirection.Out, edgePredicate: i => i.Name == "e1", recursive: true).Should().BeEquivalentTo(v2);
        }