File tree Expand file tree Collapse file tree 2 files changed +15
-3
lines changed
de.vogella.datastructures.list
src/de/vogella/datastructures/list
test/de/vogella/datastructures/list Expand file tree Collapse file tree 2 files changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ private void ensureCapa() {
2626
2727 @ SuppressWarnings ("unchecked" )
2828 public E get (int i ) {
29- if (i >= elements . length ) {
29+ if (i >= size || i < 0 ) {
3030 throw new IndexOutOfBoundsException ("Index: " + i + ", Size " + i );
3131 }
3232 return (E ) elements [i ];
Original file line number Diff line number Diff line change @@ -21,7 +21,19 @@ public void testMyList() {
2121 assertTrue (2 == list .get (1 ));
2222 assertTrue (3 == list .get (2 ));
2323
24- list .get (100 );
24+ list .get (6 );
25+ }
26+
27+
28+ @ Test (expected =IndexOutOfBoundsException .class )
29+ public void testNegative () {
30+ MyList <Integer > list = new MyList <Integer >();
31+ list .add (1 );
32+ list .add (2 );
33+ list .add (3 );
34+ list .add (3 );
35+ list .add (4 );
36+ list .get (-1 );
2537 }
2638
2739 @ Test (expected =IndexOutOfBoundsException .class )
@@ -36,7 +48,7 @@ public void testList() {
3648 assertTrue (2 == list .get (1 ));
3749 assertTrue (3 == list .get (2 ));
3850
39- list .get (100 );
51+ list .get (6 );
4052 }
4153
4254
You can’t perform that action at this time.
0 commit comments