public void InsertionSortStepTest_if_Array_Has_Step_4_startIndex_0() { int[] testArr = { 6, 2, 5, 4, 1, 2, 7 }; Array.ForEach(testArr, (item) => Console.Write(item + " ")); Console.WriteLine(); int step = 4; int startIndex = 0; SortLevel.InsertionSortStep(testArr, step, startIndex); foreach (int item in testArr) { Console.Write(item + " "); } Console.WriteLine(); int[] expectedSortedArr = new int[] { 1, 2, 5, 4, 6, 2, 7 }; for (int i = 0; i < testArr.Length; i++) { Assert.AreEqual(expectedSortedArr[i], testArr[i]); } }
public void InsertionSortStep_if_Array_is_Empty() { int[] testArr = { }; SortLevel.InsertionSortStep(testArr, 5, 0); Assert.IsNotNull(testArr); Assert.IsTrue(testArr.Length == 0); }
public void InsertionSortStep_if_Array_Has_1_Elem() { int[] testArr = { 19 }; SortLevel.InsertionSortStep(testArr, 12, 0); int expected = 19; Assert.IsNotNull(testArr); Assert.IsTrue(testArr.Length == 1); Assert.AreEqual(expected, testArr[0]); }
public void InsertionSortStepSingle6() { //arrange int[] array = new int[] { 1, 6, 5, 4, 3, 2, 7 }; int[] expected = new int[] { 1, 3, 5, 4, 6, 2, 7 }; //act SortLevel.InsertionSortStep(array, 3, 1); //assert for (int i = 0; i < array.Length; i++) { Assert.AreEqual(expected[i], array[i]); } }
public void InsertionSortStepSingle3() { //arrange int[] array = new int[] { 8, 4, 5, 11, 2, 1 }; int[] expected = new int[] { 5, 4, 8, 11, 2, 1 }; //act SortLevel.InsertionSortStep(array, 2, 0); //assert for (int i = 0; i < array.Length; i++) { Assert.AreEqual(expected[i], array[i]); } }
public void InsertionSortStepSingle2() { //arrange int[] array = new int[] { 7, 4, 1, 3, 2 }; int[] expected = new int[] { 2, 4, 1, 3, 7 }; //act SortLevel.InsertionSortStep(array, 4, 0); //assert for (int i = 0; i < array.Length; i++) { Assert.AreEqual(expected[i], array[i]); } }
public void InsertionSortStepSingle1() { //arrange int[] array = new int[] { 0, 0, 1, 0, 0 }; int[] expected = new int[] { 0, 0, 0, 1, 0 }; //act SortLevel.InsertionSortStep(array, 1, 2); //assert for (int i = 0; i < array.Length; i++) { Assert.AreEqual(expected[i], array[i]); } }
public void InsertionSortStepTest_if_Array_Has_3_Elements() { int[] testArr = { 3, 4, 2 }; Array.ForEach(testArr, (item) => Console.Write(item + " ")); Console.WriteLine(); SortLevel.InsertionSortStep(testArr, 1, 0); foreach (int item in testArr) { Console.Write(item + " "); } Console.WriteLine(); int[] expectedSortedArr = new int[] { 2, 3, 4 }; for (int i = 0; i < testArr.Length; i++) { Assert.AreEqual(expectedSortedArr[i], testArr[i]); } }
public static void TestInsertionSortStep() { var array = new int[] { 7, 6, 5, 4, 3, 2, 1 }; SortLevel.InsertionSortStep(array, 3, 0); var ethalon = new int[] { 1, 6, 5, 4, 3, 2, 7 }; Assert.AreEqual(ethalon.Length, array.Length); for (int i = 0; i < array.Length; i++) { Assert.AreEqual(ethalon[i], array[i]); } SortLevel.InsertionSortStep(array, 3, 1); var ethalon2 = new int[] { 1, 3, 5, 4, 6, 2, 7 }; Assert.AreEqual(ethalon2.Length, array.Length); for (int i = 0; i < array.Length; i++) { Assert.AreEqual(ethalon2[i], array[i]); } }
public void InsertionSortStep() { var opt1 = new int[] { 7, 6, 5, 4, 3, 2, 1 }; var etalon1 = new int[] { 1, 6, 5, 4, 3, 2, 7 }; var etalon2 = new int[] { 1, 2, 3, 4 }; var opt2 = new int[] { 4, 3, 2, 1 }; var opt3 = new int[] { 1, 6, 5, 4, 3, 2, 7 }; var etalon3 = new int[] { 1, 3, 5, 4, 6, 2, 7 }; SortLevel.InsertionSortStep(opt2, 1, 0); SortLevel.InsertionSortStep(opt1, 3, 0); SortLevel.InsertionSortStep(opt3, 3, 1); for (int i = 0; i < opt1.Length; i++) { if (etalon1[i] != opt1[i]) { Assert.Fail(); } } for (int i = 0; i < opt2.Length; i++) { if (etalon2[i] != opt2[i]) { Assert.Fail(); } } for (int i = 0; i < opt3.Length; i++) { if (etalon3[i] != opt3[i]) { Assert.Fail(); } } }