Exemplo n.º 1
0
    public static int[,] GetMatrix(int size)
    {
        var matrix = new SpiralMatrix(size);

        matrix.Fill();
        return(matrix._matrix);
    }
    public void Empty_spiral()
    {
        var spiral = new int[, ] {
        };

        Assert.Equal(spiral, SpiralMatrix.GetMatrix(0));
    }
Exemplo n.º 3
0
        public void SpiralOrderTests()
        {
            SpiralMatrix obj = new SpiralMatrix();

            int[,] array2D = new int[, ] {
                { 1, 2, 3, 4 }, { 12, 13, 14, 5 }, { 11, 16, 15, 6 }, { 10, 9, 8, 7 }
            };

            var x = obj.SpiralOrder(array2D);


            array2D = new int[, ] {
                { 1, 2, 3, 4 }, { 5, 6, 7, 8 }, { 9, 10, 11, 12 }
            };
            x = obj.SpiralOrder(array2D);

            array2D = new int[, ] {
                { 1, 2, 3 }, { 8, 9, 4 }, { 7, 6, 5 }
            };
            x = obj.SpiralOrder(array2D);

            array2D = new int[, ] {
                { 1, 2 }, { 4, 3 }
            };
            x = obj.SpiralOrder(array2D);
        }
Exemplo n.º 4
0
        public void Test02()
        {
            var instance = new SpiralMatrix();
            var res      = instance.FillMatrix(3);

            res = instance.FillMatrix(4);
        }
Exemplo n.º 5
0
    public void Trivial_spiral()
    {
        var expected = new[, ]
        {
            { 1 }
        };

        Assert.Equal(expected, SpiralMatrix.GetMatrix(1));
    }
    public void Trivial_spiral()
    {
        var spiral = new int[, ]
        {
            { 1 }
        };

        Assert.Equal(spiral, SpiralMatrix.GetMatrix(1));
    }
    public void Spiral_of_size_2()
    {
        var spiral = new int[, ]
        {
            { 1, 2 },
            { 4, 3 }
        };

        Assert.Equal(spiral, SpiralMatrix.GetMatrix(2));
    }
Exemplo n.º 8
0
    public void Spiral_of_size_2()
    {
        var expected = new[, ]
        {
            { 1, 2 },
            { 4, 3 }
        };

        Assert.Equal(expected, SpiralMatrix.GetMatrix(2));
    }
Exemplo n.º 9
0
        /// <summary>
        /// Solve the problem
        /// </summary>
        /// <returns>The sum result</returns>
        private BigNumber Solve()
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();
            SpiralMatrix m = new SpiralMatrix(this.Limit);

            sw.Stop();
            Console.WriteLine("Elapsed: {0}s, {1}ms", sw.Elapsed.Seconds, sw.Elapsed.Milliseconds);
            return(m.MatrixSum);
        }
Exemplo n.º 10
0
    public void Spiral_of_size_3()
    {
        var spiral = new int[, ]
        {
            { 1, 2, 3 },
            { 8, 9, 4 },
            { 7, 6, 5 }
        };

        Assert.Equal(spiral, SpiralMatrix.GetMatrix(3));
    }
Exemplo n.º 11
0
    public void Spiral_of_size_3()
    {
        var expected = new[, ]
        {
            { 1, 2, 3 },
            { 8, 9, 4 },
            { 7, 6, 5 }
        };

        Assert.Equal(expected, SpiralMatrix.GetMatrix(3));
    }
Exemplo n.º 12
0
    public void Spiral_of_size_4()
    {
        var spiral = new int[, ]
        {
            { 1, 2, 3, 4 },
            { 12, 13, 14, 5 },
            { 11, 16, 15, 6 },
            { 10, 9, 8, 7 }
        };

        Assert.Equal(spiral, SpiralMatrix.GetMatrix(4));
    }
Exemplo n.º 13
0
    public void Spiral_of_size_4()
    {
        var expected = new[, ]
        {
            { 1, 2, 3, 4 },
            { 12, 13, 14, 5 },
            { 11, 16, 15, 6 },
            { 10, 9, 8, 7 }
        };

        Assert.Equal(expected, SpiralMatrix.GetMatrix(4));
    }
Exemplo n.º 14
0
        public void GetsSpiral()
        {
            var input  = Grid.BuildJaggedGridOne();
            var result = SpiralMatrix.GetSpiral(input);

            Assert.Equal("123456789", string.Join(string.Empty, result));

            var inputTwo  = Grid.BuildJaggedGridTwo();
            var resultTwo = SpiralMatrix.GetSpiral(inputTwo);

            Assert.Equal("123456789123", string.Join(string.Empty, resultTwo));
        }
Exemplo n.º 15
0
        public void SpiralOrderTest(int[][] v1, int[][] v2)
        {
            var          target = v2[0];
            SpiralMatrix test   = new SpiralMatrix();
            var          check  = test.SpiralOrder(v1);

            Assert.AreEqual(target.Length, check.Count);

            for (int i = 0; i < target.Length; i++)
            {
                Assert.AreEqual(target[i], check[i]);
            }
        }
Exemplo n.º 16
0
    public void Spiral_of_size_5()
    {
        var expected = new[, ]
        {
            { 1, 2, 3, 4, 5 },
            { 16, 17, 18, 19, 6 },
            { 15, 24, 25, 20, 7 },
            { 14, 23, 22, 21, 8 },
            { 13, 12, 11, 10, 9 }
        };

        Assert.Equal(expected, SpiralMatrix.GetMatrix(5));
    }
Exemplo n.º 17
0
        public void SpiralMatrixTest()
        {
            var nums = new int[, ] {
                { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 }
            };

            var spiral = SpiralMatrix.Spiral(nums);

            IList <int> result = new List <int> {
                1, 2, 3, 6, 9, 8, 7, 4, 5
            };

            CollectionAssert.AreEqual(result.ToArray(), spiral.ToArray());
        }
Exemplo n.º 18
0
    public void Spiral_of_size_6()
    {
        var spiral = new int[, ]
        {
            { 1, 2, 3, 4, 5, 6 },
            { 20, 21, 22, 23, 24, 7 },
            { 19, 32, 33, 34, 25, 8 },
            { 18, 31, 36, 35, 26, 9 },
            { 17, 30, 29, 28, 27, 10 },
            { 16, 15, 14, 13, 12, 11 },
        };

        Assert.Equal(spiral, SpiralMatrix.GetMatrix(6));
    }
Exemplo n.º 19
0
        public void Given_NullMatrix_Then_ProduceNull()
        {
            // Arrange
            int[][] input = null;

            int[][] expected = null;

            // Act
            var spiralGenerator = new SpiralMatrix();
            var actual = spiralGenerator.Run(input);

            // Assert
            CollectionAssert.AreEqual(expected, actual);
        }
Exemplo n.º 20
0
        public void BiggerMatrixTest()
        {
            var nums = new int[, ] {
                { 1, 2, 3, 12, 13 }, { 4, 5, 6, 45, 46 }, { 7, 8, 9, 78, 79 }
            };

            var spiral = SpiralMatrix.Spiral(nums);

            var result = new List <int> {
                1, 2, 3, 12, 13, 46, 79, 78, 9, 8, 7, 4, 5, 6, 45
            };

            CollectionAssert.AreEqual(result.ToArray(), spiral.ToArray());
        }
Exemplo n.º 21
0
    public void Spiral_of_size_7()
    {
        var spiral = new int[, ]
        {
            { 1, 2, 3, 4, 5, 6, 7 },
            { 24, 25, 26, 27, 28, 29, 8 },
            { 23, 40, 41, 42, 43, 30, 9 },
            { 22, 39, 48, 49, 44, 31, 10 },
            { 21, 38, 47, 46, 45, 32, 11 },
            { 20, 37, 36, 35, 34, 33, 12 },
            { 19, 18, 17, 16, 15, 14, 13 },
        };

        Assert.Equal(spiral, SpiralMatrix.GetMatrix(7));
    }
Exemplo n.º 22
0
        public void TestMethod2()
        {
            // Arrange
            SpiralMatrix question = new SpiralMatrix();

            int[,] matrix = new int[, ] {
                { 1, 2, 3, 4 }, { 5, 6, 7, 8 }, { 9, 10, 11, 12 }
            };
            IList <int> expected = new int[] { 1, 2, 3, 4, 8, 12, 11, 10, 9, 5, 6, 7 };

            // Act
            IList <int> actual = question.SpiralOrder(matrix);

            // Assert
            CollectionAssert.AreEqual((int[])expected, (int[])actual);
        }
Exemplo n.º 23
0
        public void TestMethod1()
        {
            // Arrange
            SpiralMatrix question = new SpiralMatrix();

            int[,] matrix = new int[, ] {
                { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 }
            };
            IList <int> expected = new int[] { 1, 2, 3, 6, 9, 8, 7, 4, 5 };

            // Act
            IList <int> actual = question.SpiralOrder(matrix);

            // Assert
            CollectionAssert.AreEqual((int[])expected, (int[])actual);
        }
Exemplo n.º 24
0
        public void Given_3By3Matrix_Then_ProduceASpiralArray()
        {
            // Arrange
            int[][] input = new []{
                                new []{ 1, 2, 3 },
                                new []{ 4, 5, 6 },
                                new []{ 7, 8, 9 }
                              };

            var expected = new[] { 1, 2, 3, 6, 9, 8, 7, 4, 5 };

            // Act
            var spiralGenerator = new SpiralMatrix();
            var actual = spiralGenerator.Run(input);

            // Assert
            CollectionAssert.AreEqual(expected, actual);
        }
Exemplo n.º 25
0
        static void Main(string[] args)
        {
            int[][] input = new int[1][];
            input[0] = new int[5] {
                1, 2, 3, 4, 5
            };
            //input[1] = new int[1] {2};
            //input[2] = new int[1] {3};
            //input[3] = new int[1] {4};

            var res = SpiralMatrix.SpiralOrder(input);

            foreach (int n in res)
            {
                Console.WriteLine(n);
            }

            Console.ReadKey();
        }
Exemplo n.º 26
0
    //////////////////////// Functions //////////////////////
    private void calculateNum(int row, int column, int amountByToReduce)
    {
        int[,] spiralMatrix;

        Debug.Log("Done: " + row + " " + column);

        spiralMatrix = SpiralMatrix.createMatrix(row, column);

        spiralPath = SpiralMatrix.spiralMatrixCounterClockwise(spiralMatrix, row, column);

        if (amountByToReduce != 0)
        {
            IEnumerable<int> range = System.Linq.Enumerable.Range((spiralPath.Count + 1) - amountByToReduce, amountByToReduce);

            foreach (int num in range)
            {
                spiralPath.Remove(num);
            }
        }
    }
Exemplo n.º 27
0
        public void Test01()
        {
            var grid = new[, ]
            {
                { 1, 2, 3 },
                { 4, 5, 6 },
                { 7, 8, 9 }
            };
            var instance = new SpiralMatrix();
            var res      = instance.PrintSpiral(grid);

            // Assert.AreEqual(new []{ 1, 2, 3, 6, 9, 8, 7, 4, 5 }, res);

            grid = new[, ]
            {
                { 1, 2, 3 },
                { 4, 5, 6 }
            };
            res = instance.PrintSpiral(grid);
            Assert.AreEqual(new[] { 1, 2, 3, 6, 5, 4 }, res);
        }
Exemplo n.º 28
0
 public void Empty_spiral()
 {
     Assert.Empty(SpiralMatrix.GetMatrix(0));
 }