Exemplo n.º 1
0
        public void SimpleArraysTest()
        {
            int[] nums1 = new int[] { 1, 2, 2, 1 };
            int[] nums2 = new int[] { 2, 2 };

            CollectionAssert.AreEquivalent(new int[] { 2, 2 }, ArrayProgram.Intersection(nums1, nums2));
        }
Exemplo n.º 2
0
        public void RotateEmptyArray()
        {
            int[] nums = new int[] { };

            ArrayProgram.RotateArray(ref nums, 3);

            CollectionAssert.AreEqual(new int[] { }, nums);
        }
Exemplo n.º 3
0
        public void RotateSmallArrayTest()
        {
            int[] nums = new int[] { 1, 2 };

            ArrayProgram.RotateArray(ref nums, 1);

            CollectionAssert.AreEqual(new int[] { 2, 1 }, nums);
        }
Exemplo n.º 4
0
        public void SimpleArrayTest()
        {
            int[] nums = new int[] { 1, 0, 2, 0, 3, 0 };

            ArrayProgram.MoveZeroes(nums);

            CollectionAssert.AreEqual(new int[] { 1, 2, 3, 0, 0, 0 }, nums);
        }
Exemplo n.º 5
0
        public void ComplexArrayTest()
        {
            int[] nums = new int[] { 0, 0, 0, 1, 0, 0, 2, 0, 3, 5, 67, 4, 5, 6, 0, 3, 4, 3, 6, 7 };

            ArrayProgram.MoveZeroes(nums);

            CollectionAssert.AreEqual(new int[] { 1, 2, 3, 5, 67, 4, 5, 6, 3, 4, 3, 6, 7, 0, 0, 0, 0, 0, 0, 0 }, nums);
        }
Exemplo n.º 6
0
        public void RotateSimpleArrayTest()
        {
            int[] nums = new int[] { 1, 2, 3, 4, 5 };

            ArrayProgram.RotateArray(ref nums, 3);

            CollectionAssert.AreEqual(new int[] { 4, 5, 1, 2, 3 }, nums);
        }
Exemplo n.º 7
0
        public void EmptyArrayTest()
        {
            int[] nums = new int[] { };

            ArrayProgram.MoveZeroes(nums);

            CollectionAssert.AreEqual(new int[] { }, nums);
        }
Exemplo n.º 8
0
    }      // end RunProgram()

    static void Main(string[] args)
    {
        ArrayProgram myArrayProgram = new ArrayProgram();

        myArrayProgram.RunProgram();
        Console.WriteLine("\n\n===============================");
        Console.WriteLine("ArrayProgram: Press any key to finish");
        Console.ReadKey();
    }
Exemplo n.º 9
0
        public void ComplexArrayTest()
        {
            int[] nums = new int[] { 230, 863, 916, 585, 981, 404, 316, 785, 88, 12, 70, 435, 384, 778, 887, 755, 740, 337, 86, 92, 325, 422, 815,
                                     650, 920, 125, 277, 336, 221, 847, 168, 23, 677, 61, 400, 136, 874, 363, 394, 199, 863, 997, 794, 587, 124,
                                     321, 212, 957, 764, 173, 314, 422, 927, 783, 930, 282, 306, 506, 44, 926, 691, 568, 68, 730, 933, 737, 531, 180,
                                     414, 751, 28, 546, 60, 371, 493, 370, 527, 387, 43, 541, 13, 457, 328, 227, 652, 365, 430, 803, 59, 858, 538,
                                     427, 583, 368, 375, 173, 809, 896, 370, 789 };

            CollectionAssert.AreEquivalent(new int[] { 28, 45 }, ArrayProgram.TwoSum(nums, 542));
        }
Exemplo n.º 10
0
        public void Rotate2x2MatrixTest()
        {
            int[,] matrix = new int[2, 2]
            {
                { 1, 2 },
                { 3, 4 }
            };

            ArrayProgram.RotateMatrix(matrix);

            CollectionAssert.AreEqual(new int[2, 2] {
                { 3, 1 }, { 4, 2 }
            }, matrix);
        }
Exemplo n.º 11
0
        public void Rotate3x3MatrixTest()
        {
            int[,] matrix = new int[3, 3]
            {
                { 1, 2, 3 },
                { 4, 5, 6 },
                { 7, 8, 9 }
            };

            ArrayProgram.RotateMatrix(matrix);

            CollectionAssert.AreEqual(new int[3, 3] {
                { 7, 4, 1 }, { 8, 5, 2 }, { 9, 6, 3 }
            }, matrix);
        }
Exemplo n.º 12
0
        public void ValidateSudokuInvalidSquareTest()
        {
            char[,] sudoku = new char[9, 9]
            {
                { '.', '8', '7', '6', '5', '4', '3', '2', '1' },
                { '2', '.', '.', '.', '.', '.', '.', '.', '.' },
                { '3', '.', '.', '.', '.', '.', '.', '.', '.' },
                { '4', '.', '.', '.', '.', '.', '.', '.', '.' },
                { '5', '.', '.', '.', '.', '.', '.', '.', '.' },
                { '6', '.', '.', '.', '.', '.', '.', '.', '.' },
                { '7', '.', '.', '.', '.', '.', '8', '.', '.' },
                { '8', '.', '.', '.', '.', '.', '.', '.', '.' },
                { '9', '.', '.', '.', '.', '.', '.', '8', '.' }
            };

            Assert.AreEqual(false, ArrayProgram.ValidateSudoku(sudoku));
        }
Exemplo n.º 13
0
        public void Rotate4x4MatrixTest()
        {
            int[,] matrix = new int[4, 4]
            {
                { 5, 1, 9, 11 },
                { 2, 4, 8, 10 },
                { 13, 3, 6, 7 },
                { 15, 14, 12, 16 }
            };

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

            ArrayProgram.RotateMatrix(matrix);

            CollectionAssert.AreEqual(result, matrix);
        }
Exemplo n.º 14
0
        public void ComplexArrayTest()
        {
            int[] nums = new int[] { 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 11, 11, 22, 22, 33, 33, 15, 77, 77, 66, 66, 88, 88, 111, 222, 111, 222 };

            Assert.AreEqual(15, ArrayProgram.FindSingle(nums));
        }
Exemplo n.º 15
0
        public void SimpleTwoSum()
        {
            int[] nums = new int[] { 1, 2, 3, 4, 5, 6, 9 };

            CollectionAssert.AreEquivalent(new int[] { 6, 5 }, ArrayProgram.TwoSum(nums, 15));
        }
Exemplo n.º 16
0
        public void SimpleCarryTest()
        {
            int[] num = new int[] { 9 };

            CollectionAssert.AreEqual(new int[] { 1, 0 }, ArrayProgram.PlusOne(num));
        }
Exemplo n.º 17
0
        public void ComplexNumberTest()
        {
            int[] num = new int[] { 9, 9, 9 };

            CollectionAssert.AreEqual(new int[] { 1, 0, 0, 0 }, ArrayProgram.PlusOne(num));
        }
Exemplo n.º 18
0
        public void EmptyArrayTest()
        {
            int[] nums = new int[] { };

            Assert.AreEqual(false, ArrayProgram.HasDuplicates(nums));
        }
Exemplo n.º 19
0
        public void SimpleNumberTest()
        {
            int[] num = new int[] { 0 };

            CollectionAssert.AreEqual(new int[] { 1 }, ArrayProgram.PlusOne(num));
        }
Exemplo n.º 20
0
        public void SimpleArrayTest()
        {
            int[] nums = new int[] { 1, 1, 2, 2, 3, 3, 4, 4, 5 };

            Assert.AreEqual(5, ArrayProgram.FindSingle(nums));
        }
Exemplo n.º 21
0
        public void SimpleArrayTest()
        {
            int[] nums = new int[] { 1, 2, 3, 4, 5 };

            Assert.AreEqual(false, ArrayProgram.HasDuplicates(nums));
        }
Exemplo n.º 22
0
        public void ComplexArrayTest()
        {
            int[] nums = new int[] { 1, 2, 4, 5, 6, 3, 2, 5, 2, 3, 4, 56, 21, 487, 675, 76576, 554, 34, 53, 65, 76, 76, 43, 43, 34, 423, 23, 3243, 3, 244, 5, 6, 43, 3, 3, 3, 3, 2, 33, 1, 3, 3, 3, 3, 3, 3, 3, 3, 1, 3, 3, 3, 3, 3, 3, 1 };

            Assert.AreEqual(true, ArrayProgram.HasDuplicates(nums));
        }