Beispiel #1
0
        public void TestAddED_RemoveED_3()
        {
            SimpleGraph graph = new SimpleGraph(4);

            graph.AddVertex(1);
            graph.AddVertex(2);
            graph.AddVertex(3);
            graph.AddVertex(4);

            graph.AddEdge(0, 1);
            graph.AddEdge(0, 2);
            graph.AddEdge(0, 3);
            graph.AddEdge(2, 3);
            Assert.IsFalse(graph.IsEdge(1, 3));
            Assert.IsFalse(graph.IsEdge(1, 2));
            Assert.IsTrue(graph.IsEdge(0, 1));
            Assert.IsTrue(graph.IsEdge(0, 2));
            Assert.IsTrue(graph.IsEdge(0, 3));
            Assert.IsTrue(graph.IsEdge(2, 3));

            graph.RemoveVertex(2);
            Assert.IsTrue(graph.vertex[2] == null);
            Assert.IsFalse(graph.IsEdge(0, 2));
            Assert.IsFalse(graph.IsEdge(2, 0));

            Assert.IsFalse(graph.IsEdge(3, 2));
        }
Beispiel #2
0
        public void TestAdd_Edge_1()
        {
            SimpleGraph graph = new SimpleGraph(5);

            graph.AddVertex(22);
            graph.AddVertex(5);
            graph.AddVertex(7);

            graph.AddEdge(0, 2);
            Assert.IsFalse(graph.IsEdge(1, 2));
            Assert.IsFalse(graph.IsEdge(0, 1));
            Assert.IsTrue(graph.IsEdge(0, 2));
        }
Beispiel #3
0
        public void TestAddED_RemoveED_2()
        {
            SimpleGraph graph = new SimpleGraph(4);

            graph.AddVertex(1);
            graph.AddVertex(2);
            graph.AddVertex(3);
            graph.AddVertex(4);

            graph.AddEdge(0, 1);
            graph.AddEdge(0, 2);
            graph.AddEdge(0, 3);
            graph.AddEdge(2, 3);
            Assert.IsFalse(graph.IsEdge(1, 3));
            Assert.IsFalse(graph.IsEdge(1, 2));
            Assert.IsTrue(graph.IsEdge(0, 1));
            Assert.IsTrue(graph.IsEdge(0, 2));
            Assert.IsTrue(graph.IsEdge(0, 3));
            Assert.IsTrue(graph.IsEdge(2, 3));

            graph.RemoveVertex(2);
            Assert.IsTrue(graph.vertex[2] == null);
            Assert.IsFalse(graph.IsEdge(0, 2));
            Assert.IsFalse(graph.IsEdge(2, 0));

            Assert.IsFalse(graph.IsEdge(2, 3));
            Assert.IsFalse(graph.IsEdge(3, 2));

            Assert.IsTrue(graph.vertex[0] != null);
            Assert.IsTrue(graph.vertex[1] != null);
            Assert.IsTrue(graph.vertex[2] == null);
            Assert.IsTrue(graph.vertex[3] != null);

            Assert.IsTrue(graph.m_adjacency[0, 0] == 0);
            Assert.IsTrue(graph.m_adjacency[0, 1] == 1);
            Assert.IsTrue(graph.m_adjacency[0, 2] == 0);
            Assert.IsTrue(graph.m_adjacency[0, 3] == 1);
            Assert.IsTrue(graph.m_adjacency[1, 0] == 1);
            Assert.IsTrue(graph.m_adjacency[1, 2] == 0);
            Assert.IsTrue(graph.m_adjacency[1, 3] == 0);
            Assert.IsTrue(graph.m_adjacency[2, 0] == 0);
            Assert.IsTrue(graph.m_adjacency[2, 1] == 0);
            Assert.IsTrue(graph.m_adjacency[2, 3] == 0);
            Assert.IsTrue(graph.m_adjacency[3, 0] == 1);
            Assert.IsTrue(graph.m_adjacency[3, 1] == 0);
            Assert.IsTrue(graph.m_adjacency[3, 2] == 0);
        }
Beispiel #4
0
        public void AddVertex()
        {
            var g = new SimpleGraph(10);

            g.AddVertex(1);
            g.AddVertex(2);

            Assert.True(!g.IsEdge(1, 2));
        }
Beispiel #5
0
        public void TestAddRemove_Edge_1()
        {
            SimpleGraph graph = new SimpleGraph(5);

            graph.AddVertex(2);
            graph.AddVertex(5);

            graph.AddEdge(0, 1);
            Assert.IsFalse(graph.IsEdge(1, 2));
            Assert.IsFalse(graph.IsEdge(4, 2));
            Assert.IsTrue(graph.IsEdge(0, 1));
            Assert.IsTrue(graph.IsEdge(1, 0));

            graph.RemoveVertex(0);
            Assert.IsTrue(graph.vertex[0] == null);
            for (int i = 0; i < graph.vertex.Length; i++)
            {
                Assert.IsTrue(graph.m_adjacency[i, 0] == 0);
                Assert.IsTrue(graph.m_adjacency[0, i] == 0);
            }
        }
Beispiel #6
0
        public void RemoveEdge()
        {
            var g = new SimpleGraph(4);

            g.AddVertex(1);
            g.AddVertex(2);

            g.AddEdge(1, 2);
            g.AddEdge(1, 1);

            Assert.True(g.IsEdge(1, 2));
            Assert.True(g.IsEdge(1, 1));

            g.RemoveEdge(1, 2);
            Assert.True(!g.IsEdge(1, 2));
            Assert.True(g.IsEdge(1, 1));

            g.RemoveEdge(1, 1);
            Assert.True(!g.IsEdge(1, 2));
            Assert.True(!g.IsEdge(1, 1));

            g.RemoveEdge(3, 3);
        }
Beispiel #7
0
        public void RemoveVertex()
        {
            var g = new SimpleGraph(10);

            g.AddVertex(1);
            g.AddVertex(2);
            g.AddVertex(3);
            g.AddVertex(4);

            Assert.True(!g.IsEdge(1, 1));
            Assert.True(!g.IsEdge(1, 2));
            Assert.True(!g.IsEdge(1, 3));
            Assert.True(!g.IsEdge(1, 4));

            Assert.True(!g.IsEdge(2, 1));
            Assert.True(!g.IsEdge(2, 2));
            Assert.True(!g.IsEdge(2, 3));
            Assert.True(!g.IsEdge(2, 4));

            Assert.True(!g.IsEdge(3, 1));
            Assert.True(!g.IsEdge(3, 2));
            Assert.True(!g.IsEdge(3, 3));
            Assert.True(!g.IsEdge(3, 4));

            Assert.True(!g.IsEdge(4, 1));
            Assert.True(!g.IsEdge(4, 2));
            Assert.True(!g.IsEdge(4, 3));
            Assert.True(!g.IsEdge(4, 4));

            g.AddEdge(1, 1);
            g.AddEdge(1, 2);
            g.AddEdge(1, 3);
            g.AddEdge(1, 4);

            g.AddEdge(2, 1);
            g.AddEdge(2, 2);
            g.AddEdge(2, 3);
            g.AddEdge(2, 4);

            g.AddEdge(3, 1);
            g.AddEdge(3, 2);
            g.AddEdge(3, 3);
            g.AddEdge(3, 4);

            g.AddEdge(4, 1);
            g.AddEdge(4, 2);
            g.AddEdge(4, 3);
            g.AddEdge(4, 4);

            Assert.True(g.IsEdge(1, 1));
            Assert.True(g.IsEdge(1, 2));
            Assert.True(g.IsEdge(1, 3));
            Assert.True(g.IsEdge(1, 4));

            Assert.True(g.IsEdge(2, 1));
            Assert.True(g.IsEdge(2, 2));
            Assert.True(g.IsEdge(2, 3));
            Assert.True(g.IsEdge(2, 4));

            Assert.True(g.IsEdge(3, 1));
            Assert.True(g.IsEdge(3, 2));
            Assert.True(g.IsEdge(3, 3));
            Assert.True(g.IsEdge(3, 4));

            Assert.True(g.IsEdge(4, 1));
            Assert.True(g.IsEdge(4, 2));
            Assert.True(g.IsEdge(4, 3));
            Assert.True(g.IsEdge(4, 4));

            g.RemoveVertex(3);

            Assert.True(g.IsEdge(1, 1));
            Assert.True(g.IsEdge(1, 2));
            Assert.True(!g.IsEdge(1, 3));
            Assert.True(g.IsEdge(1, 4));

            Assert.True(g.IsEdge(2, 1));
            Assert.True(g.IsEdge(2, 2));
            Assert.True(!g.IsEdge(2, 3));
            Assert.True(g.IsEdge(2, 4));

            Assert.True(!g.IsEdge(3, 1));
            Assert.True(!g.IsEdge(3, 2));
            Assert.True(!g.IsEdge(3, 3));
            Assert.True(!g.IsEdge(3, 4));

            Assert.True(g.IsEdge(4, 1));
            Assert.True(g.IsEdge(4, 2));
            Assert.True(!g.IsEdge(4, 3));
            Assert.True(g.IsEdge(4, 4));
        }
Beispiel #8
0
        public void TestAdd_Edge_2()
        {
            SimpleGraph graph = new SimpleGraph(5);

            graph.AddVertex(22);
            graph.AddVertex(5);
            graph.AddVertex(7);
            graph.AddVertex(11);
            graph.AddVertex(52);
            graph.AddVertex(27);
            for (int i = 0; i < graph.max_vertex; i++)
            {
                Assert.IsTrue(graph.vertex[i].Value != 27);
            }


            graph.AddEdge(1, 4);
            graph.AddEdge(3, 4);
            graph.AddEdge(0, 1);
            Assert.IsFalse(graph.IsEdge(1, 2));
            Assert.IsFalse(graph.IsEdge(1, 3));
            Assert.IsFalse(graph.IsEdge(2, 0));
            Assert.IsFalse(graph.IsEdge(2, 1));
            Assert.IsFalse(graph.IsEdge(2, 3));
            Assert.IsFalse(graph.IsEdge(3, 0));
            Assert.IsFalse(graph.IsEdge(3, 1));
            Assert.IsFalse(graph.IsEdge(3, 2));
            Assert.IsFalse(graph.IsEdge(4, 0));
            Assert.IsFalse(graph.IsEdge(4, 2));

            Assert.IsTrue(graph.IsEdge(4, 1));
            Assert.IsTrue(graph.IsEdge(1, 4));
            Assert.IsTrue(graph.IsEdge(3, 4));
            Assert.IsTrue(graph.IsEdge(4, 3));
            Assert.IsTrue(graph.IsEdge(0, 1));
            Assert.IsTrue(graph.IsEdge(1, 0));
        }
Beispiel #9
0
        public void SimpleGraphTest()
        {
            //SimpleGraph graph = new SimpleGraph(4);

            int[] arr = { 10, 15, 21, 23 };

            foreach (int item in arr)
            {
                graph.AddVertex(item);
                for (int i = 0; i < graph.max_vertex; i++)
                {
                    if (graph.vertex[i] != null)
                    {
                        if (graph.vertex[i].Value == item)
                        {
                            for (int j = 0; j < graph.max_vertex; j++)
                            {
                                if (graph.IsEdge(i, j))
                                {
                                    Assert.Fail();
                                }
                            }
                        }
                    }
                }
            }
        }
Beispiel #10
0
 public void TestIsEdge()
 {
     Assert.IsFalse(_graph.IsEdge(0, 0));
     Assert.IsTrue(_graph.IsEdge(0, 1));
     Assert.IsFalse(_graph.IsEdge(1, 1));
     Assert.IsFalse(_graph.IsEdge(2, 2));
     Assert.IsTrue(_graph.IsEdge(3, 3));
     Assert.IsTrue(_graph.IsEdge(3, 1));
 }
Beispiel #11
0
        public void RemoveEdge_5e_in_5v_Graph()
        {
            int size = 5;
            SimpleGraph <int> testGraph = new SimpleGraph <int>(size);

            testGraph.AddVertex(19);
            testGraph.AddVertex(18);
            testGraph.AddVertex(17);
            testGraph.AddVertex(16);
            testGraph.AddVertex(15);

            Assert.IsTrue(testGraph.vertex[0].Value == 19);
            Assert.IsTrue(testGraph.vertex[1].Value == 18);
            Assert.IsTrue(testGraph.vertex[2].Value == 17);
            Assert.IsTrue(testGraph.vertex[3].Value == 16);
            Assert.IsTrue(testGraph.vertex[4].Value == 15);

            Assert.AreEqual(size, testGraph.max_vertex);
            Assert.AreEqual(size, testGraph.vertex.Length);
            Assert.AreEqual(size, testGraph.m_adjacency.GetLength(0));
            Assert.AreEqual(size, testGraph.m_adjacency.GetLength(1));
            Assert.AreEqual(0, testGraph.m_adjacency[0, 2]);
            Assert.AreEqual(0, testGraph.m_adjacency[2, 0]);


            testGraph.AddEdge(0, 1); // добавление ребра между вершинами
            testGraph.AddEdge(0, 2);
            testGraph.AddEdge(0, 3);
            testGraph.AddEdge(2, 1);
            testGraph.AddEdge(2, 3);

            Assert.IsTrue(testGraph.IsEdge(0, 1)); // проверка добавления ребёр
            Assert.IsTrue(testGraph.IsEdge(0, 2));
            Assert.IsTrue(testGraph.IsEdge(0, 3));
            Assert.IsTrue(testGraph.IsEdge(2, 1));
            Assert.IsTrue(testGraph.IsEdge(2, 3));

            for (int i = 0; i < testGraph.m_adjacency.GetLength(0); i++)
            {
                for (int j = 0; j < testGraph.m_adjacency.GetLength(1); j++)
                {
                    Console.Write(testGraph.m_adjacency[i, j] + " ");
                }
                Console.WriteLine();
            }

            Assert.AreEqual(1, testGraph.m_adjacency[0, 1]);
            Assert.AreEqual(1, testGraph.m_adjacency[0, 2]);
            Assert.AreEqual(1, testGraph.m_adjacency[0, 3]);
            Assert.AreEqual(1, testGraph.m_adjacency[1, 0]);
            Assert.AreEqual(1, testGraph.m_adjacency[1, 2]);
            Assert.AreEqual(1, testGraph.m_adjacency[2, 0]);
            Assert.AreEqual(1, testGraph.m_adjacency[2, 1]);
            Assert.AreEqual(1, testGraph.m_adjacency[2, 3]);
            Assert.AreEqual(1, testGraph.m_adjacency[3, 0]);
            Assert.AreEqual(1, testGraph.m_adjacency[3, 2]);

            testGraph.RemoveEdge(0, 1); // удаление ребер между вершинами
            testGraph.RemoveEdge(0, 2);
            testGraph.RemoveEdge(0, 3);
            testGraph.RemoveEdge(2, 1);
            testGraph.RemoveEdge(2, 3);

            for (int i = 0; i < testGraph.m_adjacency.GetLength(0); i++)
            {
                for (int j = 0; j < testGraph.m_adjacency.GetLength(1); j++)
                {
                    Console.Write(testGraph.m_adjacency[i, j] + " ");
                }
                Console.WriteLine();
            }
        }