Skip to content

Commit a626e6c

Browse files
committed
updates
1 parent 63809db commit a626e6c

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

de.vogella.datastructures.list/src/de/vogella/datastructures/list/MyList.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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];

de.vogella.datastructures.list/test/de/vogella/datastructures/list/MyListTest.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)