public void BinaryMinHeapBuildTest() { var heap = new BinaryMinHeapClass(new int[] { 45, 15, 10, 5 }); heap.Items.ToArray().Should().BeEquivalentTo(new int[] { 5, 15, 10, 45 }); heap = new BinaryMinHeapClass(new int[] { 5, 4, 3, 2, 1 }); heap.Items.ToArray().Should().BeEquivalentTo(new int[] { 1, 2, 3, 5, 4 }); heap = new BinaryMinHeapClass(new int[] { 8, 9, 9, 3, 5, 6, 20, 10, 12, 18 }); heap.Items.ToArray().Should().BeEquivalentTo(new int[] { 3, 5, 9, 6, 8, 20, 10, 12, 18, 9 }); }
public void ExtractMinTest() { var heap = new BinaryMinHeapClass(new int[] { 45 }); heap.Insert(15); heap.Insert(10); heap.Insert(5); heap.Insert(25); heap.Insert(35); heap.Items.Should().BeEquivalentTo(new int[] { 5, 15, 10, 25, 35, 45 }); }
public void GetMinTest() { var heap = new BinaryMinHeapClass(new int[] { 45, 15, 10, 5 }); heap.GetMin().Should().Be(5); heap.ExtractMin(); heap.GetMin().Should().Be(10); heap.ExtractMin(); heap.GetMin().Should().Be(15); heap.ExtractMin(); heap.GetMin().Should().Be(45); heap.ExtractMin(); }
public void ExtractMinTest() { var heap = new BinaryMinHeapClass(new int[] { 45, 15, 10, 5 }); var first = heap.ExtractMin(); var second = heap.ExtractMin(); var third = heap.ExtractMin(); var fourth = heap.ExtractMin(); Action fifth = () => heap.ExtractMin(); first.Should().Be(5); second.Should().Be(10); third.Should().Be(15); fourth.Should().Be(45); fifth.Should().Throw <Exception>() .WithMessage("Heap empty"); }