Esempio n. 1
0
        public void TestRemovEdge()
        {
            var graph = new Graph();

            var v1 = new StringVertex("a");
            var v2 = new StringVertex("b");
            var e  = new StringEdge(v1, v2, "c");

            // should fail if edge is not in graph
            Assert.ThrowsException <ArgumentException>(() => graph.RemoveEdge(e));
        }
Esempio n. 2
0
        public void Test3()
        {
            var graph = new Graph();

            var v1 = new StringVertex("blue");

            graph.AddVertex(v1);
            var v2 = new StringVertex("green");

            graph.AddVertex(v2);
            var v3 = new StringVertex("yellow");

            graph.AddVertex(v3);
            var v4 = new StringVertex("yellow");

            graph.AddVertex(v4);
            var v5 = new StringVertex("blue");

            graph.AddVertex(v5);
            var v6 = new StringVertex("green");

            graph.AddVertex(v6);

            graph.AddEdge(new StringEdge(v1, v4, "green"));
            graph.AddEdge(new StringEdge(v2, v5, "yellow"));
            graph.AddEdge(new StringEdge(v3, v6, "blue"));
            graph.AddEdge(new StringEdge(v4, v5, "green"));
            graph.AddEdge(new StringEdge(v5, v6, "yellow"));
            graph.AddEdge(new StringEdge(v6, v4, "blue"));

            var pattern = new Graph();

            var vp1 = new StringVertex("yellow");

            pattern.AddVertex(vp1);
            var vp2 = new StringVertex("blue");

            pattern.AddVertex(vp2);
            var vp3 = new StringVertex("green");

            pattern.AddVertex(vp3);

            pattern.AddEdge(new StringEdge(vp1, vp2, "green"));
            pattern.AddEdge(new StringEdge(vp2, vp3, "yellow"));
            pattern.AddEdge(new StringEdge(vp3, vp1, "blue"));

            Assert.IsNotNull(graph.FindPattern(pattern));

            var vp4 = new StringVertex("green");

            pattern.AddVertex(vp4);
            // wrong edge color
            var ef = new StringEdge(vp2, vp4, "blue");

            pattern.AddEdge(ef);

            Assert.IsNull(graph.FindPattern(pattern));
            pattern.RemoveEdge(ef);

            Assert.ThrowsException <System.ArgumentException>(() => pattern.AddVertex(vp4));
            var ef2 = new DataEdge <float>(vp2, vp4, 4.2f);

            pattern.AddEdge(ef2);
            Assert.IsNull(graph.FindPattern(pattern));
        }