Exemple #1
0
        public void TestAddNodeMultipleDifferent()
        {
            AdjacencyList <int> graph = new AdjacencyList <int>();

            graph.AddNode(1);
            graph.AddNode(2);

            Assert.AreEqual(2, graph.Count);
        }
Exemple #2
0
        public void TestAddEdgeBothDoNotExist()
        {
            AdjacencyList <int> graph = new AdjacencyList <int>();

            graph.AddNode(1);
            graph.AddNode(2);

            bool success = graph.AddEdge(3, 4);

            Assert.IsFalse(success);
        }
Exemple #3
0
        public void TestAddEdge()
        {
            AdjacencyList <int> graph = new AdjacencyList <int>();

            graph.AddNode(1);
            graph.AddNode(2);

            bool success = graph.AddEdge(1, 2);

            Assert.AreEqual(2, graph.Count);
            Assert.IsTrue(success);
        }
Exemple #4
0
        public void TestAddNodeFailsAlreadyExists()
        {
            AdjacencyList <int> graph = new AdjacencyList <int>();

            graph.AddNode(1);
            Assert.AreEqual(1, graph.Count);

            bool success = graph.AddNode(1);

            Assert.IsFalse(success);
            Assert.AreEqual(1, graph.Count);
        }
        public void VertexFind(NewEdgeDefinition vertexClick, MouseEventArgs e, List <VertexDraw> vertexDraws, List <EdgeDraw> edgeDraws, ref int startVertexId, ref int endVertexId,
                               ref AdjacencyList adjacencyList, AdjacencyListPanel adListPanel, MatrixWeightPanel matrixWeightPanel)
        {
            vertexClick.VertexRemember(ref startVertexId, ref endVertexId
                                       , e.X - (int)VertexParameters.Radius, e.Y - (int)VertexParameters.Radius
                                       , vertexDraws);


            if ((startVertexId != -1) && (endVertexId != -1) && (startVertexId != endVertexId) && (!IsDuplicate(edgeDraws, startVertexId, endVertexId)))
            {
                EdgeDraw edgeDraw = new EdgeDraw(BrushColor.Black, 0, startVertexId, endVertexId);

                edgeDraws.Add(edgeDraw);

                adjacencyList.AddNode(startVertexId, endVertexId, 1);

                adListPanel.UpdateNodesPanel(startVertexId, endVertexId);

                matrixWeightPanel.UpdateNodes(startVertexId, endVertexId);

                startVertexId = -1;
                endVertexId   = -1;
            }
            else if (IsDuplicate(edgeDraws, startVertexId, endVertexId))
            {
                startVertexId = -1;
                endVertexId   = -1;
            }
        }
Exemple #6
0
        public void TestAddNodeSingle()
        {
            AdjacencyList <int> graph = new AdjacencyList <int>();

            graph.AddNode(1);

            Assert.AreEqual(1, graph.Count);
        }
Exemple #7
0
        public void TestAddEdgeSourceDoesNotExist()
        {
            AdjacencyList <int> graph = new AdjacencyList <int>();

            graph.AddNode(2);

            bool success = graph.AddEdge(1, 2);

            Assert.IsFalse(success);
        }
Exemple #8
0
        public void TestGetAccessor()
        {
            AdjacencyList <int> graph = new AdjacencyList <int>();

            int one = 1;
            int two = 2;

            graph.AddNode(one);
            graph.AddNode(two);

            bool        success  = graph.AddEdge(one, two);
            IList <int> oneEdges = graph[one];
            IList <int> twoEdges = graph[two];

            Assert.IsTrue(success);
            Assert.AreEqual(one, oneEdges.Count);
            Assert.AreEqual(two, oneEdges[0]);

            Assert.AreEqual(0, twoEdges.Count);
        }
Exemple #9
0
        private void AddNeighboursToGraph(AdjacencyList <Vertex2D> graph, int x, int y)
        {
            var node       = new Vertex2D(x, y);
            var neighbours = GetLocationNeighbours(node);

            graph.AddNode(node);
            foreach (var element in neighbours)
            {
                graph.AddNeighbour(node, new Node <Vertex2D>(element, 1));
            }
        }
Exemple #10
0
        public void TestAddNodeSeveral()
        {
            AdjacencyList <int> graph = new AdjacencyList <int>();
            int ceiling = 100;

            for (int i = 0; i < ceiling; i++)
            {
                graph.AddNode(i);
            }

            Assert.AreEqual(ceiling, graph.Count);
        }
Exemple #11
0
        public void TestGetEnumerator()
        {
            List <int[]> expecteds = new List <int[]>
            {
                new int[] { 2, 3 },
                new int[] { 3 },
                new int[] { 1 },
            };

            AdjacencyList <int> graph = new AdjacencyList <int>();

            int one   = 1;
            int two   = 2;
            int three = 3;

            graph.AddNode(one);
            graph.AddNode(two);
            graph.AddNode(three);

            graph.AddEdge(one, two);
            graph.AddEdge(one, three);
            graph.AddEdge(two, three);
            graph.AddEdge(three, one);


            IEnumerator <KeyValuePair <int, List <int> > > enumerator = graph.GetEnumerator();

            Assert.IsNotNull(enumerator);

            KeyValuePair <int, List <int> > current;

            while (enumerator.MoveNext())
            {
                current = enumerator.Current;
                Assert.AreEqual(expecteds[current.Key - 1], current.Value);
            }
        }
Exemple #12
0
        public void TestGetEdgesNotInGraph()
        {
            AdjacencyList <int> graph = new AdjacencyList <int>();

            graph.AddNode(1);
            try
            {
                graph.GetEdges(2);
            }
            catch (KeyNotFoundException)
            {
                Assert.Pass();
            }
            Assert.Fail("Exception not thrown");
        }
Exemple #13
0
        public AdjacencyList <TNode, TWeight> GetDepthFirstSearchGraph()
        {
            AdjacencyList <TNode, TWeight> result = new AdjacencyList <TNode, TWeight>(this.NumberOfNodes);

            foreach (TNode item in this.labels.Keys)
            {
                result.AddNode(item);
            }

            for (int i = 0; i < this.NumberOfNodes; i++)
            {
                if (this.labels.Values[i].Predecessor != null)
                {
                    result.AddDirectedEdge(this.labels.Values[i].Predecessor.Value, this.labels.Values[i].Value, new TWeight());
                }
            }

            return(result);
        }
        public void AddNodeTest_CreateLoop_ExceptionExpected()
        {
            var ex = Assert.Throws <System.Exception>(() => adList.AddNode(vertex.Id, vertex.Id, 20));

            Assert.AreEqual(ex.Message, "The starting vertex coincides with the ending vertex");
        }