public void ShouldHandleFullyOverlapedNodes()
        {
            var compressParameters = new CompressParameters {
                MaxReferenceListSize = 10
            };
            var similarNodeList = new List <SimilarNode>()
            {
                new SimilarNode
                {
                    Node1      = 1,
                    Neighbors1 = new SortedList <int, int> {
                        { 1, 3 }, { 2, 4 }, { 3, 5 }
                    }
                },
                new SimilarNode
                {
                    Node1      = 2,
                    Node2      = 1,
                    Neighbors1 = new SortedList <int, int> {
                        { 1, 3 }, { 2, 4 }, { 3, 5 }
                    },
                    Neighbors2 = new SortedList <int, int> {
                        { 1, 3 }, { 2, 4 }, { 3, 5 }
                    }
                }
            };

            var expectedResult = new CompressedGraph();

            expectedResult.AddNode(new CompressedNode
            {
                Id         = 1,
                ExtraNodes = new SortedSet <int> {
                    3, 4, 5
                }
            });
            expectedResult.AddNode(new CompressedNode
            {
                Id            = 2,
                ExtraNodes    = new SortedSet <int>(),
                ReferenceId   = 1,
                ReferenceList = new BitArray(new bool[] { true, true, true })
            });


            var result = ExecuteTest(similarNodeList, compressParameters);

            CheckExpectedAgainstResult(expectedResult, result);
        }
        public void ShouldHandleNodeWithoutReference()
        {
            var compressParameters = new CompressParameters {
                MaxReferenceListSize = 10
            };
            var similarNodeList = new List <SimilarNode>()
            {
                new SimilarNode
                {
                    Node1      = 1,
                    Neighbors1 = new SortedList <int, int> {
                        { 1, 3 }, { 2, 4 }, { 3, 5 }
                    }
                }
            };

            var expectedResult = new CompressedGraph();

            expectedResult.AddNode(new CompressedNode
            {
                Id         = 1,
                ExtraNodes = new SortedSet <int> {
                    3, 4, 5
                }
            });


            var result = ExecuteTest(similarNodeList, compressParameters);

            CheckExpectedAgainstResult(expectedResult, result);
        }
        private CompressedGraph CreateCompressedGraph(IGraph graph, int[] directGraphOfSimilaNode)
        {
            var compressedGraph = new CompressedGraph();

            for (int i = 0; i < directGraphOfSimilaNode.Length; i++)
            {
                var nodeId        = i;
                var similarNodeId = directGraphOfSimilaNode[i];

                var node = graph.GetNode(nodeId);

                var compressedNode = new CompressedNode
                {
                    Id = nodeId,
                };

                if (similarNodeId == -1)
                {
                    compressedNode.ExtraNodes = new SortedSet <int>(node.Neighbors);
                }
                else
                {
                    var similarNode = graph.GetNode(similarNodeId);

                    var referenceList = GetReferenceListAndExtraNodes(node, similarNode);
                    var extraNodes    = GetExtraNodes(node, similarNode);

                    compressedNode.ReferenceList = referenceList;
                    compressedNode.ExtraNodes    = extraNodes;
                    compressedNode.ReferenceId   = similarNodeId;
                }

                compressedGraph.AddNode(compressedNode);
            }

            return(compressedGraph);
        }
        public void ShouldHandleMaxReferenceListOverstepWithBoundaries()
        {
            var compressParameters = new CompressParameters {
                MaxReferenceListSize = 2
            };
            var similarNodeList = new List <SimilarNode>()
            {
                new SimilarNode
                {
                    Node1      = 1,
                    Node2      = 2,
                    Neighbors1 = new SortedList <int, int> {
                        { 1, 30 }, { 2, 40 }
                    },
                    Neighbors2 = new SortedList <int, int> {
                        { 1, 30 }, { 2, 40 }, { 3, 50 }
                    }
                },
                new SimilarNode
                {
                    Node1      = 3,
                    Node2      = 4,
                    Neighbors1 = new SortedList <int, int> {
                        { 1, 70 }, { 2, 80 }
                    },
                    Neighbors2 = new SortedList <int, int> {
                        { 1, 70 }, { 2, 80 }
                    }
                },
                new SimilarNode
                {
                    Node1      = 5,
                    Node2      = 6,
                    Neighbors1 = new SortedList <int, int> {
                        { 1, 75 }, { 2, 85 }
                    },
                    Neighbors2 = new SortedList <int, int> {
                        { 1, 75 }
                    }
                },
            };

            var expectedResult = new CompressedGraph();

            expectedResult.AddNode(new CompressedNode
            {
                Id         = 1,
                ExtraNodes = new SortedSet <int>()
                {
                    30, 40
                },
            });
            expectedResult.AddNode(new CompressedNode
            {
                Id            = 3,
                ReferenceId   = 4,
                ReferenceList = new BitArray(new bool[] { true, true }),
                ExtraNodes    = new SortedSet <int>(),
            });

            expectedResult.AddNode(new CompressedNode
            {
                Id            = 5,
                ReferenceId   = 6,
                ReferenceList = new BitArray(new bool[] { true }),
                ExtraNodes    = new SortedSet <int> {
                    85
                },
            });

            var result = ExecuteTest(similarNodeList, compressParameters);

            CheckExpectedAgainstResult(expectedResult, result);
        }
        public void ShouldHandleNotMappedReferences()
        {
            var compressParameters = new CompressParameters {
                MaxReferenceListSize = 5
            };
            var similarNodeList = new List <SimilarNode>()
            {
                new SimilarNode
                {
                    Node1      = 1,
                    Node2      = 2,
                    Neighbors1 = new SortedList <int, int> {
                        { 1, 30 }, { 2, 40 }
                    },
                    Neighbors2 = new SortedList <int, int> {
                        { 1, 30 }
                    }
                },
                new SimilarNode
                {
                    Node1      = 3,
                    Node2      = 4,
                    Neighbors1 = new SortedList <int, int> {
                        { 1, 70 }, { 2, 80 }
                    },
                    Neighbors2 = new SortedList <int, int> {
                    }
                },
                new SimilarNode
                {
                    Node1      = 5,
                    Node2      = 6,
                    Neighbors1 = new SortedList <int, int> {
                        { 1, 75 }, { 2, 85 }
                    },
                    Neighbors2 = new SortedList <int, int> {
                        { 1, 85 }, { 2, 90 }
                    }
                },
                new SimilarNode
                {
                    Node1      = 7,
                    Node2      = 8,
                    Neighbors1 = new SortedList <int, int> {
                        { 1, 90 }, { 2, 96 }
                    },
                    Neighbors2 = new SortedList <int, int> {
                        { 1, 85 }, { 2, 88 }
                    }
                },
            };

            var expectedResult = new CompressedGraph();

            expectedResult.AddNode(new CompressedNode
            {
                Id            = 1,
                ReferenceId   = 2,
                ReferenceList = new BitArray(new bool[] { true }),
                ExtraNodes    = new SortedSet <int>()
                {
                    40
                },
            });
            expectedResult.AddNode(new CompressedNode
            {
                Id            = 3,
                ReferenceId   = 4,
                ReferenceList = new BitArray(0),
                ExtraNodes    = new SortedSet <int>()
                {
                    70, 80
                },
            });

            expectedResult.AddNode(new CompressedNode
            {
                Id            = 5,
                ReferenceId   = 6,
                ReferenceList = new BitArray(new bool[] { true, false }),
                ExtraNodes    = new SortedSet <int> {
                    75
                },
            });

            expectedResult.AddNode(new CompressedNode
            {
                Id            = 7,
                ReferenceId   = 8,
                ReferenceList = new BitArray(new bool[] { false, false }),
                ExtraNodes    = new SortedSet <int> {
                    90, 96
                },
            });

            var result = ExecuteTest(similarNodeList, compressParameters);

            CheckExpectedAgainstResult(expectedResult, result);
        }