11package com .jwetherell .algorithms .data_structures .test ;
22
33import static org .junit .Assert .assertTrue ;
4+ import static org .junit .Assert .assertNull ;
45
56import java .util .Collection ;
67
@@ -16,7 +17,7 @@ public class BinaryHeapTests {
1617
1718 @ Test
1819 public void testMinHeap () {
19- TestData data = Utils .generateTestData (100 );
20+ TestData data = Utils .generateTestData (2500 );
2021
2122 String aNameMin = "Min-Heap [array]" ;
2223 BinaryHeap .BinaryHeapArray <Integer > aHeapMin = new BinaryHeap .BinaryHeapArray <Integer >(BinaryHeap .Type .MIN );
@@ -26,18 +27,31 @@ public void testMinHeap() {
2627 assertTrue (JavaCollectionTest .testCollection (aCollectionMin , Integer .class , aNameMin ,
2728 data .unsorted , data .sorted , data .invalid ));
2829
30+ BinaryHeap .BinaryHeapArray <Integer > aHeapNull = new BinaryHeap .BinaryHeapArray <Integer >(BinaryHeap .Type .MIN );
31+ aHeapNull .add (10 );
32+ aHeapNull .add (11 );
33+ aHeapNull .clear ();
34+ assertNull (aHeapNull .getHeadValue ()); // we expect null here
35+
2936 String tNameMin = "Min-Heap [tree]" ;
3037 BinaryHeap .BinaryHeapTree <Integer > tHeapMin = new BinaryHeap .BinaryHeapTree <Integer >(BinaryHeap .Type .MIN );
3138 Collection <Integer > tCollectionMin = tHeapMin .toCollection ();
3239 assertTrue (HeapTest .testHeap (BinaryHeap .Type .MIN , tHeapMin , Integer .class , tNameMin ,
3340 data .unsorted , data .sorted , data .invalid ));
3441 assertTrue (JavaCollectionTest .testCollection (tCollectionMin , Integer .class , tNameMin ,
3542 data .unsorted , data .sorted , data .invalid ));
43+
44+ BinaryHeap .BinaryHeapTree <Integer > tHeapNull = new BinaryHeap .BinaryHeapTree <Integer >(BinaryHeap .Type .MIN );
45+ tHeapNull .add (10 );
46+ tHeapNull .add (11 );
47+ tHeapNull .clear ();
48+ assertNull (tHeapNull .getHeadValue ()); // we expect null here
49+
3650 }
3751
3852 @ Test
3953 public void testMaxHeap () {
40- TestData data = Utils .generateTestData (1000 );
54+ TestData data = Utils .generateTestData (2500 );
4155
4256 String aNameMax = "Max-Heap [array]" ;
4357 BinaryHeap .BinaryHeapArray <Integer > aHeapMax = new BinaryHeap .BinaryHeapArray <Integer >(BinaryHeap .Type .MAX );
@@ -47,12 +61,24 @@ public void testMaxHeap() {
4761 assertTrue (JavaCollectionTest .testCollection (aCollectionMax , Integer .class , aNameMax ,
4862 data .unsorted , data .sorted , data .invalid ));
4963
64+ BinaryHeap .BinaryHeapArray <Integer > aHeapNull = new BinaryHeap .BinaryHeapArray <Integer >(BinaryHeap .Type .MAX );
65+ aHeapNull .add (10 );
66+ aHeapNull .add (11 );
67+ aHeapNull .clear ();
68+ assertNull (aHeapNull .getHeadValue ()); // we expect null here
69+
5070 String lNameMax = "Max-Heap [tree]" ;
5171 BinaryHeap .BinaryHeapTree <Integer > tHeapMax = new BinaryHeap .BinaryHeapTree <Integer >(BinaryHeap .Type .MAX );
5272 Collection <Integer > tCollectionMax = tHeapMax .toCollection ();
5373 assertTrue (HeapTest .testHeap (BinaryHeap .Type .MAX , tHeapMax , Integer .class , lNameMax ,
5474 data .unsorted , data .sorted , data .invalid ));
5575 assertTrue (JavaCollectionTest .testCollection (tCollectionMax , Integer .class , lNameMax ,
5676 data .unsorted , data .sorted , data .invalid ));
77+
78+ BinaryHeap .BinaryHeapTree <Integer > tHeapNull = new BinaryHeap .BinaryHeapTree <Integer >(BinaryHeap .Type .MAX );
79+ tHeapNull .add (10 );
80+ tHeapNull .add (11 );
81+ tHeapNull .clear ();
82+ assertNull (tHeapNull .getHeadValue ()); // we expect null here
5783 }
5884}
0 commit comments