public void DoesNotPartitionArraysWithTwoItems() { // Arrange var pivot = new Pivot(new[] { 0, 0 }); // Act var result = pivot.Partition(0, 0, 0); // Assert Assert.AreEqual(-1, result); }
public void SucceedsOnRandomArray() { // Arrange var array = GetRandomArray(); var pivot = new Pivot(array); // Act var result = pivot.Partition(0, array.Length - 1, 450); // Assert AssertItemsLeftOfPivotAreLessThanIt(array, result); AssertItemsRightOfPivotAreGreaterOrEqualOfIt(array, result); }
public void ThreeItemsArray() { // Arrange var array = new[] { 10, 5, 1 }; var pivot = new Pivot(array); // Act var result = pivot.Partition(0, array.Length - 1, 5); // Assert Assert.AreEqual(1, result); Assert.AreEqual(1, array[0]); Assert.AreEqual(5, array[1]); Assert.AreEqual(10, array[2]); }
public void PivotDoesNotNeedToExistOnArrayForPartitionToWork() { // Arrange var array = new[] { 10, 5, 1, 8 }; var pivot = new Pivot(array); // Act var result = pivot.Partition(0, array.Length - 1, 2); // Assert Assert.AreEqual(1, result); Assert.AreEqual(1, array[0]); Assert.AreEqual(5, array[1]); Assert.IsTrue(array[2] > 5); Assert.IsTrue(array[3] > 5); }
public void FiveItemsArray() { // Arrange var array = new[] { 10, 5, 1, 8, -63 }; var pivot = new Pivot(array); // Act var result = pivot.Partition(0, array.Length - 1, 5); // Assert Assert.AreEqual(2, result); Assert.IsTrue(array[0] < 5); Assert.IsTrue(array[1] < 5); Assert.AreEqual(5, array[2]); Assert.IsTrue(array[3] > 5); Assert.IsTrue(array[4] > 5); }