Ejemplo n.º 1
0
        public void TestArrayRotation()
        {
            int[]          arr = { 1, 2, 3, 4, 5, 6, 7 };
            ArraysProblems ap  = new ArraysProblems();

            ap.Rotate(arr, 3);
        }
Ejemplo n.º 2
0
        public void TestArrayReverseSubarray()
        {
            ArraysProblems ap = new ArraysProblems();

            int[] arr = { 1, 2, 3, 4, 5, 6, 7 };
            ap.ReverseSubArray(arr, 0, 4);
            Assert.IsTrue(arr[0] == 5);
        }
Ejemplo n.º 3
0
        public void TestArrayReverse()
        {
            ArraysProblems ap = new ArraysProblems();

            int[] arr = { 1, 2, 3, 4, 5, 6, 7 };
            ap.Reverse(arr);
            Assert.IsTrue(arr[0] == 7);
        }
Ejemplo n.º 4
0
        public void TestQuickSelect()
        {
            ArraysProblems ap = new ArraysProblems();

            int[] arr = { 7, 3, 1, 4, 2, 9 };
            var   j   = ap.QuickSelect(arr, 3);

            Assert.IsTrue(j == 3, "Third smallest is 3");
            Assert.IsTrue(ap.QuickSelect(arr, 5) == 7, "5th smallest is 7");
        }
Ejemplo n.º 5
0
        public void TestArrayRotateOptimal()
        {
            ArraysProblems ap = new ArraysProblems();

            int[] arr = { 1, 2, 3, 4, 5, 6, 7 };
            ap.Rotate_Optimal(arr, 3);
            Assert.IsTrue(arr[0] == 5);

            arr = new int[] { 1, 2, 3, 4, 5, 6, 7 };
            ap.Rotate_Optimal(arr, 4);
            Assert.IsTrue(arr[0] == 4);

            arr = new int[] { 1, 2, 3, 4, 5, 6, 7 };
            ap.Rotate_Optimal(arr, 7);
            Assert.IsTrue(arr[0] == 1);

            arr = new int[] { 1, 2, 3, 4, 5, 6, 7 };
            ap.Rotate_Optimal(arr, 8);
            Assert.IsTrue(arr[0] == 7);
        }