コード例 #1
0
        public void TestTrue()
        {
            // arrange
            string path1 = @"D:\matrix3.txt"; string path2 = @"D:\matrix2.txt";
            Matrix matrTest = new Matrix(path1);
            Matrix matrCheck = new Matrix(path2);
            int[] arr = new int[matrTest.Columns * matrTest.Rows];
            Direction direct = new Direction();

            //act
            matrTest.PassageMatrix(ref arr, 0, 0, 0, matrTest.Rows, matrTest.Columns, direct);

            // Assert
            CollectionAssert.AreEqual(matrCheck.GetMatrix, arr);
        }
コード例 #2
0
        public void PassageMatrix(ref int[] arr, int linearPosition, int positionR, int positionC, int numRows, int numColumns, Direction direction)
        {
            if(numColumns !=0 && numRows!=0)
            {
                switch (direction.CurrentDirection)
                {
                    case "right":
                        {
                            for (int i=positionC; i<positionC+numColumns; i++)
                            {
                                arr[linearPosition] = matrix[positionR, i];
                                linearPosition++;
                                
                            }

                            direction.SwitchDirection();
                            PassageMatrix(ref arr, linearPosition, positionR + 1, positionC + numColumns - 1, numRows - 1, numColumns, direction);
                            break;
                        }

                    case "down":
                        {
                            for (int i = positionR; i < positionR+numRows; i++)
                            {
                                arr[linearPosition] = matrix[i, positionC];
                                linearPosition++;

                            }

                            direction.SwitchDirection();
                            PassageMatrix(ref arr, linearPosition, positionR +numRows- 1, positionC - 1, numRows , numColumns-1, direction);
                            break;
                        }

                    case "left":
                        {
                            for (int i = positionC; i >=positionC+1-numColumns; i--)
                            {
                                arr[linearPosition] = matrix[positionR, i];
                                linearPosition++;

                            }

                            direction.SwitchDirection();
                            PassageMatrix(ref arr, linearPosition, positionR -1, positionC - numColumns + 1, numRows - 1, numColumns, direction);
                            break;
                        }

                    case "up":
                        {
                            for (int i = positionR; i >=positionR+1-numRows; i--)
                            {
                                arr[linearPosition] = matrix[i, positionC];
                                linearPosition++;

                            }

                            direction.SwitchDirection();
                            PassageMatrix(ref arr, linearPosition, positionR+1-numRows , positionC + 1, numRows, numColumns - 1, direction);
                            break;
                        }

                }

            }


            //recursion exit (do nothing)
            

        }
コード例 #3
0
        static void Main(string[] args)
        {
            Matrix matrTest = new Matrix(@"D:\matrix3.txt");
            Matrix matrCheck = new Matrix(@"D:\matrix2.txt");
            int[] arr = new int[matrTest.Columns * matrTest.Rows];
            Direction direct = new Direction();

            //act
            matrTest.PassageMatrix(ref arr, 0, 0, 0, matrTest.Rows, matrTest.Columns, direct);

            foreach(int val in arr)
            {
                Console.Write(" ");
                Console.Write(val);
            }

            Console.ReadKey();
        }