public void TestLiveEdgeDynamicGraphAddRemove1()
        {
            using (var graph = new MemoryMappedGraph<LiveEdge>(1000, 1024))
            {
                uint tagsId = 10;
                var vertex1 = graph.AddVertex(51, 1);
                var vertex2 = graph.AddVertex(51, 2);

                graph.AddEdge(vertex1, vertex2, new LiveEdge()
                {
                    Forward = true,
                    Tags = tagsId
                }, null);

                // test forward edge.
                var arcs = graph.GetEdges(vertex1).ToKeyValuePairs();
                Assert.AreEqual(1, arcs.Length);
                Assert.AreEqual(tagsId, arcs[0].Value.Tags);
                Assert.AreEqual(vertex2, arcs[0].Key);
                Assert.AreEqual(true, arcs[0].Value.Forward);

                // remove edge again.
                graph.RemoveEdge(vertex1, vertex2);

                // check if the edge is gone.
                arcs = graph.GetEdges(vertex1).ToKeyValuePairs();
                Assert.AreEqual(0, arcs.Length);
            }
        }
        public void TestLiveEdgeDynamicGraphAddRemove1()
        {
            using (var graph = new MemoryMappedGraph <LiveEdge>(1000, 1024))
            {
                uint tagsId  = 10;
                var  vertex1 = graph.AddVertex(51, 1);
                var  vertex2 = graph.AddVertex(51, 2);

                graph.AddEdge(vertex1, vertex2, new LiveEdge()
                {
                    Forward = true,
                    Tags    = tagsId
                }, null);

                // test forward edge.
                var arcs = graph.GetEdges(vertex1).ToKeyValuePairs();
                Assert.AreEqual(1, arcs.Length);
                Assert.AreEqual(tagsId, arcs[0].Value.Tags);
                Assert.AreEqual(vertex2, arcs[0].Key);
                Assert.AreEqual(true, arcs[0].Value.Forward);

                // remove edge again.
                graph.RemoveEdge(vertex1, vertex2);

                // check if the edge is gone.
                arcs = graph.GetEdges(vertex1).ToKeyValuePairs();
                Assert.AreEqual(0, arcs.Length);
            }
        }
        public void TestLiveEdgeDynamicGraphRemoveAll()
        {
            using (var graph = new MemoryMappedGraph <LiveEdge>(1000, 1024))
            {
                var vertex1 = graph.AddVertex(51, 1);
                var vertex2 = graph.AddVertex(51, 2);
                var vertex3 = graph.AddVertex(51, 3);
                var vertex4 = graph.AddVertex(51, 3);

                graph.AddEdge(vertex1, vertex2, new LiveEdge()
                {
                    Forward = true,
                    Tags    = 1
                });
                graph.AddEdge(vertex2, vertex3, new LiveEdge()
                {
                    Forward = true,
                    Tags    = 2
                });
                graph.AddEdge(vertex3, vertex4, new LiveEdge()
                {
                    Forward = true,
                    Tags    = 3
                });

                graph.AddEdge(vertex4, vertex2, new LiveEdge()
                {
                    Forward = true,
                    Tags    = 4
                });

                graph.RemoveEdge(vertex2, vertex1);
                graph.RemoveEdge(vertex2, vertex3);
                graph.RemoveEdge(vertex4, vertex3);
                graph.RemoveEdge(vertex4, vertex2);
                Assert.IsFalse(graph.ContainsEdges(vertex2, vertex1));
                Assert.IsFalse(graph.ContainsEdges(vertex2, vertex3));
                Assert.IsFalse(graph.ContainsEdges(vertex4, vertex3));
                Assert.IsFalse(graph.ContainsEdges(vertex4, vertex2));
            }
        }
        public void TestLiveEdgeDynamicGraphAddRemove2()
        {
            using (var graph = new MemoryMappedGraph <LiveEdge>(1000, 1024))
            {
                uint tagsId  = 10;
                var  vertex1 = graph.AddVertex(51, 1);
                var  vertex2 = graph.AddVertex(51, 2);
                var  vertex3 = graph.AddVertex(51, 3);

                graph.AddEdge(vertex1, vertex2, new LiveEdge()
                {
                    Forward = true,
                    Tags    = tagsId
                }, null);

                graph.AddEdge(vertex2, vertex3, new LiveEdge()
                {
                    Forward = true,
                    Tags    = tagsId
                }, null);

                // test edges.
                var edges = graph.GetEdges(vertex1).ToKeyValuePairs();
                Assert.AreEqual(1, edges.Length);
                Assert.AreEqual(tagsId, edges[0].Value.Tags);
                Assert.AreEqual(vertex2, edges[0].Key);
                Assert.AreEqual(true, edges[0].Value.Forward);
                edges = graph.GetEdges(vertex2).ToKeyValuePairs();
                Assert.AreEqual(2, edges.Length);
                edges = graph.GetEdges(vertex3).ToKeyValuePairs();
                Assert.AreEqual(1, edges.Length);
                Assert.AreEqual(tagsId, edges[0].Value.Tags);
                Assert.AreEqual(vertex2, edges[0].Key);
                Assert.AreEqual(false, edges[0].Value.Forward);

                // remove edge again.
                graph.RemoveEdge(vertex1, vertex2);

                // test edges.
                edges = graph.GetEdges(vertex1).ToKeyValuePairs();
                Assert.AreEqual(0, edges.Length);
                edges = graph.GetEdges(vertex2).ToKeyValuePairs();
                Assert.AreEqual(1, edges.Length);
                Assert.AreEqual(tagsId, edges[0].Value.Tags);
                Assert.AreEqual(vertex3, edges[0].Key);
                Assert.AreEqual(true, edges[0].Value.Forward);
                edges = graph.GetEdges(vertex3).ToKeyValuePairs();
                Assert.AreEqual(1, edges.Length);
                Assert.AreEqual(tagsId, edges[0].Value.Tags);
                Assert.AreEqual(vertex2, edges[0].Key);
                Assert.AreEqual(false, edges[0].Value.Forward);
            }
        }
        public void TestLiveEdgeDynamicGraphRemoveBegin()
        {
            using (var graph = new MemoryMappedGraph <LiveEdge>(1000, 1024))
            {
                var vertex1 = graph.AddVertex(51, 1);
                var vertex2 = graph.AddVertex(51, 2);
                var vertex3 = graph.AddVertex(51, 3);
                var vertex4 = graph.AddVertex(51, 3);

                graph.AddEdge(vertex1, vertex2, new LiveEdge()
                {
                    Forward = true,
                    Tags    = 1
                }, null);
                graph.AddEdge(vertex2, vertex3, new LiveEdge()
                {
                    Forward = true,
                    Tags    = 2
                }, null);
                graph.AddEdge(vertex3, vertex4, new LiveEdge()
                {
                    Forward = true,
                    Tags    = 3
                }, null);

                graph.AddEdge(vertex4, vertex2, new LiveEdge()
                {
                    Forward = true,
                    Tags    = 4
                }, null);

                graph.RemoveEdge(vertex2, vertex1);
                Assert.IsFalse(graph.ContainsEdges(vertex2, vertex1));
                Assert.IsFalse(graph.ContainsEdges(vertex1, vertex2));

                Assert.AreEqual(graph.GetEdges(vertex1).ToKeyValuePairs().Length, 0);
                Assert.AreEqual(graph.GetEdges(vertex2).ToKeyValuePairs().Length, 2);
                Assert.AreEqual(graph.GetEdges(vertex3).ToKeyValuePairs().Length, 2);
                Assert.AreEqual(graph.GetEdges(vertex4).ToKeyValuePairs().Length, 2);
            }
        }
        public void TestLiveEdgeDynamicGraphAddRemove2()
        {
            using (var graph = new MemoryMappedGraph<LiveEdge>(1000, 1024))
            {
                uint tagsId = 10;
                var vertex1 = graph.AddVertex(51, 1);
                var vertex2 = graph.AddVertex(51, 2);
                var vertex3 = graph.AddVertex(51, 3);

                graph.AddEdge(vertex1, vertex2, new LiveEdge()
                {
                    Forward = true,
                    Tags = tagsId
                }, null);

                graph.AddEdge(vertex2, vertex3, new LiveEdge()
                {
                    Forward = true,
                    Tags = tagsId
                }, null);

                // test edges.
                var edges = graph.GetEdges(vertex1).ToKeyValuePairs();
                Assert.AreEqual(1, edges.Length);
                Assert.AreEqual(tagsId, edges[0].Value.Tags);
                Assert.AreEqual(vertex2, edges[0].Key);
                Assert.AreEqual(true, edges[0].Value.Forward);
                edges = graph.GetEdges(vertex2).ToKeyValuePairs();
                Assert.AreEqual(2, edges.Length);
                edges = graph.GetEdges(vertex3).ToKeyValuePairs();
                Assert.AreEqual(1, edges.Length);
                Assert.AreEqual(tagsId, edges[0].Value.Tags);
                Assert.AreEqual(vertex2, edges[0].Key);
                Assert.AreEqual(false, edges[0].Value.Forward);

                // remove edge again.
                graph.RemoveEdge(vertex1, vertex2);

                // test edges.
                edges = graph.GetEdges(vertex1).ToKeyValuePairs();
                Assert.AreEqual(0, edges.Length);
                edges = graph.GetEdges(vertex2).ToKeyValuePairs();
                Assert.AreEqual(1, edges.Length);
                Assert.AreEqual(tagsId, edges[0].Value.Tags);
                Assert.AreEqual(vertex3, edges[0].Key);
                Assert.AreEqual(true, edges[0].Value.Forward);
                edges = graph.GetEdges(vertex3).ToKeyValuePairs();
                Assert.AreEqual(1, edges.Length);
                Assert.AreEqual(tagsId, edges[0].Value.Tags);
                Assert.AreEqual(vertex2, edges[0].Key);
                Assert.AreEqual(false, edges[0].Value.Forward);
            }
        }
        public void TestLiveEdgeDynamicGraphRemoveMiddle()
        {
            using (var graph = new MemoryMappedGraph<LiveEdge>(1000, 1024))
            {
                var vertex1 = graph.AddVertex(51, 1);
                var vertex2 = graph.AddVertex(51, 2);
                var vertex3 = graph.AddVertex(51, 3);
                var vertex4 = graph.AddVertex(51, 3);

                graph.AddEdge(vertex1, vertex2, new LiveEdge()
                {
                    Forward = true,
                    Tags = 1
                }, null);
                graph.AddEdge(vertex2, vertex3, new LiveEdge()
                {
                    Forward = true,
                    Tags = 2
                }, null);
                graph.AddEdge(vertex3, vertex4, new LiveEdge()
                {
                    Forward = true,
                    Tags = 3
                }, null);

                graph.AddEdge(vertex4, vertex2, new LiveEdge()
                {
                    Forward = true,
                    Tags = 4
                }, null);

                graph.RemoveEdge(vertex2, vertex3);
                Assert.IsFalse(graph.ContainsEdge(vertex2, vertex3));
                Assert.IsFalse(graph.ContainsEdge(vertex3, vertex2));

                Assert.AreEqual(graph.GetEdges(vertex1).ToKeyValuePairs().Length, 1);
                Assert.AreEqual(graph.GetEdges(vertex2).ToKeyValuePairs().Length, 2);
                Assert.AreEqual(graph.GetEdges(vertex3).ToKeyValuePairs().Length, 1);
                Assert.AreEqual(graph.GetEdges(vertex4).ToKeyValuePairs().Length, 2);
            }
        }
        public void TestLiveEdgeDynamicGraphRemoveAll()
        {
            using (var graph = new MemoryMappedGraph<LiveEdge>(1000, 1024))
            {
                var vertex1 = graph.AddVertex(51, 1);
                var vertex2 = graph.AddVertex(51, 2);
                var vertex3 = graph.AddVertex(51, 3);
                var vertex4 = graph.AddVertex(51, 3);

                graph.AddEdge(vertex1, vertex2, new LiveEdge()
                {
                    Forward = true,
                    Tags = 1
                });
                graph.AddEdge(vertex2, vertex3, new LiveEdge()
                {
                    Forward = true,
                    Tags = 2
                });
                graph.AddEdge(vertex3, vertex4, new LiveEdge()
                {
                    Forward = true,
                    Tags = 3
                });

                graph.AddEdge(vertex4, vertex2, new LiveEdge()
                {
                    Forward = true,
                    Tags = 4
                });

                graph.RemoveEdge(vertex2, vertex1);
                graph.RemoveEdge(vertex2, vertex3);
                graph.RemoveEdge(vertex4, vertex3);
                graph.RemoveEdge(vertex4, vertex2);
                Assert.IsFalse(graph.ContainsEdge(vertex2, vertex1));
                Assert.IsFalse(graph.ContainsEdge(vertex2, vertex3));
                Assert.IsFalse(graph.ContainsEdge(vertex4, vertex3));
                Assert.IsFalse(graph.ContainsEdge(vertex4, vertex2));
            }
        }
        public void TestLiveEdgeDynamicGraphCompressEdges()
        {
            using (var graph = new MemoryMappedGraph <LiveEdge>(1000, 1024))
            {
                var vertex1 = graph.AddVertex(51, 1);
                var vertex2 = graph.AddVertex(51, 2);
                var vertex3 = graph.AddVertex(51, 3);
                var vertex4 = graph.AddVertex(51, 3);

                graph.AddEdge(vertex1, vertex2, new LiveEdge()
                {
                    Forward = true,
                    Tags    = 1
                }, null);
                graph.AddEdge(vertex2, vertex3, new LiveEdge()
                {
                    Forward = true,
                    Tags    = 2
                }, null);
                graph.AddEdge(vertex3, vertex4, new LiveEdge()
                {
                    Forward = true,
                    Tags    = 3
                }, null);

                graph.AddEdge(vertex4, vertex2, new LiveEdge()
                {
                    Forward = true,
                    Tags    = 4
                }, null);

                graph.RemoveEdge(vertex2, vertex3);

                graph.Compress();

                Assert.IsFalse(graph.ContainsEdges(vertex2, vertex3));
                Assert.IsFalse(graph.ContainsEdges(vertex3, vertex2));

                Assert.AreEqual(graph.GetEdges(vertex1).ToKeyValuePairs().Length, 1);
                Assert.AreEqual(graph.GetEdges(vertex2).ToKeyValuePairs().Length, 2);
                Assert.AreEqual(graph.GetEdges(vertex3).ToKeyValuePairs().Length, 1);
                Assert.AreEqual(graph.GetEdges(vertex4).ToKeyValuePairs().Length, 2);
            }

            using (var graph = new MemoryMappedGraph <LiveEdge>(1000, 1024))
            {
                uint vertex1 = graph.AddVertex(51, 1);
                uint vertex2 = graph.AddVertex(51, 2);
                uint vertex3 = graph.AddVertex(51, 3);
                uint vertex4 = graph.AddVertex(51, 3);

                graph.AddEdge(vertex1, vertex2, new LiveEdge()
                {
                    Forward = true,
                    Tags    = 1
                }, null);
                graph.AddEdge(vertex2, vertex3, new LiveEdge()
                {
                    Forward = true,
                    Tags    = 2
                }, null);
                graph.AddEdge(vertex3, vertex4, new LiveEdge()
                {
                    Forward = true,
                    Tags    = 3
                }, null);

                graph.AddEdge(vertex4, vertex2, new LiveEdge()
                {
                    Forward = true,
                    Tags    = 4
                }, null);

                graph.RemoveEdge(vertex3, vertex4);

                graph.Compress();

                Assert.IsFalse(graph.ContainsEdges(vertex3, vertex4));
                Assert.IsFalse(graph.ContainsEdges(vertex4, vertex3));

                Assert.AreEqual(graph.GetEdges(vertex1).ToKeyValuePairs().Length, 1);
                Assert.AreEqual(graph.GetEdges(vertex2).ToKeyValuePairs().Length, 3);
                Assert.AreEqual(graph.GetEdges(vertex3).ToKeyValuePairs().Length, 1);
                Assert.AreEqual(graph.GetEdges(vertex4).ToKeyValuePairs().Length, 1);

                LiveEdge edge;
                Assert.IsTrue(graph.GetEdge(vertex1, vertex2, out edge));
                Assert.AreEqual(1, edge.Tags);
                Assert.IsTrue(graph.GetEdge(vertex2, vertex3, out edge));
                Assert.AreEqual(2, edge.Tags);
                Assert.IsTrue(graph.GetEdge(vertex4, vertex2, out edge));
                Assert.AreEqual(4, edge.Tags);
            }
        }