Example #1
0
        public void CheckTest2()
        {
            // Arrange
            var indexes = new int[2][];

            indexes[0]    = new int[2];
            indexes[0][0] = 2;
            indexes[0][1] = 3;

            indexes[1]    = new int[2];
            indexes[1][0] = 4;
            indexes[1][1] = 5;

            var swapNodes = new SwapNodesAlgo();

            var root    = swapNodes.BuildTree(indexes).Item1;
            var queries = new int[1];

            queries[0] = 2;

            // Act
            var result = swapNodes.Swap(indexes, queries);

            // Assert
            Assert.Equal(5, result[0][0]);
            Assert.Equal(2, result[0][1]);
            Assert.Equal(4, result[0][2]);
            Assert.Equal(1, result[0][3]);
            Assert.Equal(3, result[0][4]);
        }
Example #2
0
        public void BuildTreeTest2()
        {
            // Arrange
            var indexes = new int[2][];

            indexes[0]    = new int[2];
            indexes[0][0] = 2;
            indexes[0][1] = 3;

            indexes[1]    = new int[2];
            indexes[1][0] = 4;
            indexes[1][1] = 5;

            var swapNodes = new SwapNodesAlgo();

            // Act
            var tree = swapNodes.BuildTree(indexes).Item2.ToList();

            // Assert
            Assert.Equal(2, tree[0].Depth);
            Assert.Equal(3, tree[0].Index);

            Assert.Equal(3, tree[1].Depth);
            Assert.Equal(4, tree[1].Index);

            Assert.Equal(3, tree[2].Depth);
            Assert.Equal(5, tree[2].Index);
        }
Example #3
0
        public void BuildRootNode()
        {
            // Arrange
            var indexes = new int[2][];

            indexes[0]    = new int[2];
            indexes[0][0] = 2;
            indexes[0][1] = 3;

            indexes[1]    = new int[2];
            indexes[1][0] = 4;
            indexes[1][1] = 5;

            var swapNodes = new SwapNodesAlgo();

            // Act
            var root = swapNodes.BuildTree(indexes).Item1;

            // Assert
            Assert.Equal(2, root.Right.Depth);
            Assert.Equal(3, root.Right.Index);

            Assert.Equal(2, root.Left.Depth);
            Assert.Equal(2, root.Left.Index);

            Assert.Equal(3, root.Left.Left.Depth);
            Assert.Equal(4, root.Left.Left.Index);

            Assert.Equal(3, root.Left.Right.Depth);
            Assert.Equal(5, root.Left.Right.Index);
        }
Example #4
0
        public void BuildTreeTest()
        {
            // Arrange
            var indexes   = new int[0][];
            var swapNodes = new SwapNodesAlgo();

            // Act
            var tree = swapNodes.BuildTree(indexes).Item2.ToList();

            // Assert
            Assert.Equal(1, tree[0].Index);
            Assert.Equal(1, tree[0].Depth);
        }
Example #5
0
        public void NodeToString()
        {
            // Arrange
            var indexes = new int[1][];

            indexes[0]    = new int[2];
            indexes[0][0] = 2;
            indexes[0][1] = 3;

            var swapNodes = new SwapNodesAlgo();

            // Act
            var root = swapNodes.BuildTree(indexes).Item1;

            // Assert
            Assert.Equal("Index:2, Depth:2", root.Left.ToString());
            Assert.Equal("Index:3, Depth:2", root.Right.ToString());
        }