コード例 #1
0
        public void BubbleSortStepTest_if_Array_is_Already_Sorted()
        {
            int[] testArr = { 1, 2, 3, 4 };
            Array.ForEach(testArr, (item) => Console.Write(item + " "));
            Console.WriteLine();

            bool res = SortLevel.BubbleSortStep(testArr);

            foreach (int item in testArr)
            {
                Console.Write(item + " ");
            }
            Console.WriteLine();

            int[] expectedSortedArr = new int[] { 1, 2, 3, 4 };

            Assert.IsNotNull(testArr);
            Assert.IsTrue(res);
            Assert.IsTrue(testArr.Length == 4);

            for (int i = 0; i < testArr.Length; i++)
            {
                Assert.AreEqual(expectedSortedArr[i], testArr[i]);
            }
        }
コード例 #2
0
        public void BubbleSortStep_if_Array_is_Empty()
        {
            int[] testArr = { };

            bool res = SortLevel.BubbleSortStep(testArr);

            Assert.IsNotNull(testArr);
            Assert.IsTrue(res);
            Assert.IsTrue(testArr.Length == 0);
        }
コード例 #3
0
        public void TestBubble_6()
        {
            int[] array = new int[] { 2, 2, 2 };
            int[] expay = new int[] { 2, 2, 2 };

            Assert.AreEqual(true, SortLevel.BubbleSortStep(array));
            for (int i = 0; i < array.Length; i++)
            {
                Assert.AreEqual(expay[i], array[i]);
            }
        }
コード例 #4
0
        public void TestBubble_2()
        {
            int[] array = new int[] { 1, 5, 3, 4, 2 };
            int[] expay = new int[] { 1, 3, 4, 2, 5 };

            Assert.AreEqual(false, SortLevel.BubbleSortStep(array));
            for (int i = 0; i < array.Length; i++)
            {
                Assert.AreEqual(expay[i], array[i]);
            }
        }
コード例 #5
0
        public static void TestBubbleSortStep()
        {
            var result  = SortLevel.BubbleSortStep(_array);
            var ethalon = new int[] { 3, 1, 2, 4 };

            Assert.IsFalse(result);
            Assert.AreEqual(ethalon.Length, _array.Length);
            for (int i = 0; i < _array.Length; i++)
            {
                Assert.AreEqual(ethalon[i], _array[i]);
            }
        }
コード例 #6
0
        public void BubbleSortStep_if_Array_Has_1_Elem()
        {
            int[] testArr = { 19 };

            bool res = SortLevel.BubbleSortStep(testArr);

            int expected = 19;

            Assert.IsNotNull(testArr);
            Assert.IsTrue(res);
            Assert.IsTrue(testArr.Length == 1);
            Assert.AreEqual(expected, testArr[0]);
        }
コード例 #7
0
        public void BubbleSortStepTest()
        {
            var arr  = new int[] { 4, 3, 1, 2 };
            var raa  = new int[] { 1, 2, 3, 4 };
            var arr1 = new int[] { 1, 2, 4, 3 };

            if (SortLevel.BubbleSortStep(arr) == true)
            {
                Assert.Fail();
            }
            if (SortLevel.BubbleSortStep(raa) == false)
            {
                Assert.Fail();
            }
            if (SortLevel.BubbleSortStep(arr1) == true)
            {
                Assert.Fail();
            }
        }
コード例 #8
0
        public void TestBubble_4()
        {
            int[] array  = new int[] { 7, 5, 3, 1, -1 };
            int[] expay1 = new int[] { 5, 3, 1, -1, 7 };
            int[] expay2 = new int[] { 3, 1, -1, 5, 7 };
            int[] expay3 = new int[] { 1, -1, 3, 5, 7 };
            int[] expay4 = new int[] { -1, 1, 3, 5, 7 };

            Assert.AreEqual(false, SortLevel.BubbleSortStep(array));
            for (int i = 0; i < array.Length; i++)
            {
                Assert.AreEqual(expay1[i], array[i]);
            }

            Assert.AreEqual(false, SortLevel.BubbleSortStep(array));
            for (int i = 0; i < array.Length; i++)
            {
                Assert.AreEqual(expay2[i], array[i]);
            }

            Assert.AreEqual(false, SortLevel.BubbleSortStep(array));
            for (int i = 0; i < array.Length; i++)
            {
                Assert.AreEqual(expay3[i], array[i]);
            }

            Assert.AreEqual(false, SortLevel.BubbleSortStep(array));
            for (int i = 0; i < array.Length; i++)
            {
                Assert.AreEqual(expay4[i], array[i]);
            }

            Assert.AreEqual(true, SortLevel.BubbleSortStep(array));
            for (int i = 0; i < array.Length; i++)
            {
                Assert.AreEqual(expay4[i], array[i]);
            }
        }
コード例 #9
0
        public void BubbleSortStepTest_if_Array_unsorted()
        {
            int[] testArr = { 4, 3, 1, 2 };
            Array.ForEach(testArr, (item) => Console.Write(item + " "));
            Console.WriteLine();

            bool res = SortLevel.BubbleSortStep(testArr);

            foreach (int item in testArr)
            {
                Console.Write(item + " ");
            }
            Console.WriteLine();

            int[] expectedSortedArr = new int[] { 3, 1, 2, 4 };

            Assert.IsFalse(res);

            for (int i = 0; i < testArr.Length; i++)
            {
                Assert.AreEqual(expectedSortedArr[i], testArr[i]);
            }
        }
コード例 #10
0
        public void TestBubble_3()
        {
            int[] array  = new int[] { 4, 3, 1, 2 };
            int[] expay1 = new int[] { 3, 1, 2, 4 };
            int[] expay2 = new int[] { 1, 2, 3, 4 };

            Assert.AreEqual(false, SortLevel.BubbleSortStep(array));
            for (int i = 0; i < array.Length; i++)
            {
                Assert.AreEqual(expay1[i], array[i]);
            }

            Assert.AreEqual(false, SortLevel.BubbleSortStep(array));
            for (int i = 0; i < array.Length; i++)
            {
                Assert.AreEqual(expay2[i], array[i]);
            }

            Assert.AreEqual(true, SortLevel.BubbleSortStep(array));
            for (int i = 0; i < array.Length; i++)
            {
                Assert.AreEqual(expay2[i], array[i]);
            }
        }