File tree Expand file tree Collapse file tree 6 files changed +62
-0
lines changed
out/production/Algorithms/ws/codelogic Expand file tree Collapse file tree 6 files changed +62
-0
lines changed Original file line number Diff line number Diff line change 1+ package ws .codelogic .algorithms .priorityqueue ;
2+
3+ public class BinaryTree <T >{
4+
5+ private T [] elements ;
6+ private int currentElement ;
7+
8+ public BinaryTree (T [] emptyArray ){
9+ elements = emptyArray ;
10+ currentElement = -1 ;
11+ }
12+
13+ public void add (T element ){
14+ elements [++currentElement ] = element ;
15+ }
16+
17+ public T remove (){
18+ return elements [currentElement --];
19+ }
20+
21+
22+ }
Original file line number Diff line number Diff line change 1+ package ws .codelogic .algorithms .priorityqueue ;
2+
3+ import org .junit .Before ;
4+ import org .junit .Test ;
5+ import static org .junit .Assert .*;
6+
7+ public class PriorityQueueTest {
8+
9+ private BinaryTree <Integer > queue ;
10+
11+ @ Before
12+ public void setUp () {
13+ Integer [] array = new Integer [5 ];
14+ queue = new BinaryTree <Integer >(array );
15+ }
16+
17+ @ Test
18+ public void adding1ObjectYeildsThatObject () {
19+ queue .add (9 );
20+ checkNumber (9 );
21+ }
22+
23+ private void checkNumber (Integer numberToTest ){
24+ Integer numberFromQueue = queue .remove ();
25+ assertEquals (numberFromQueue , numberToTest );
26+ }
27+
28+ @ Test
29+ public void adding3ObjectYeildsThoseObjectsInOrder () {
30+ queue .add (5 );
31+ queue .add (1 );
32+ queue .add (9 );
33+ checkNumber (9 );
34+ checkNumber (5 );
35+ checkNumber (1 );
36+ }
37+
38+ }
Original file line number Diff line number Diff line change 55import ws .codelogic .algorithms .Stack .ArrayStackTest ;
66import ws .codelogic .algorithms .Stack .LinkStackTest ;
77import ws .codelogic .algorithms .arithmetic .evaluation .DijkstrasTwoStackTest ;
8+ import ws .codelogic .algorithms .priorityqueue .PriorityQueueTest ;
89import ws .codelogic .algorithms .search .SearchTest ;
910import ws .codelogic .algorithms .selection .QuickSelectTest ;
1011import ws .codelogic .algorithms .shuffle .ShufflerTest ;
1415
1516@ RunWith (Suite .class )
1617@ Suite .SuiteClasses ({
18+ PriorityQueueTest .class ,
1719 Dijkstras3WayPartitionTest .class ,
1820 QuickSelectTest .class ,
1921 QuickSortTest .class ,
You can’t perform that action at this time.
0 commit comments