define more edge cases

main
Lukas Klipfel 2026-01-16 16:54:21 +01:00
parent 08fd3f0f1f
commit 63493bb3f0
2 changed files with 16 additions and 10 deletions

View File

@ -15,16 +15,16 @@ Achtung! Die Methoden müssen für die Aufgabe ein wenig angepasst werden.
| Methode | Parameter | Rückgabetyp | Rückgabewert | | Methode | Parameter | Rückgabetyp | Rückgabewert |
| - | - | - | - | | - | - | - | - |
| add(String n) | n: String to be appended | void | add(String n) | n: String to be appended | void
| add(int index, String n) | index: index at which the specified String is to be inserted <br> n: String to be inserted | Boolean | true: erfolgreich <br> false: fehlgeschlagen | add(int index, String n) | index: index at which the specified String is to be inserted <br> n: String to be inserted | Boolean | true: erfolgreich <br> false: fehlgeschlagen (out of bounds)
| addAll(MeineArrayList liste) | liste: list wich gets appended | void | | addAll(MeineArrayList liste) | liste: list wich gets appended | void |
| addAll(int index, MeineArrayList liste) | index: index at which to insert the first element <br> list: list containing Strings to be added to this list | Boolean | true: erfolgreich <br> false: fehlgeschlagen | addAll(int index, MeineArrayList liste) | index: index at which to insert the first element <br> list: list containing Strings to be added to this list | Boolean | true: erfolgreich <br> false: fehlgeschlagen (out of bounds)
clear() | | void | | clear() | | void | |
contains(String s) | s: String to search | Boolean | true: the same String exists (s.eaquals()) in the list <br> false: the String doesn't exists in the list. contains(String s) | s: String to search | Boolean | true: the same String exists (s.eaquals()) in the list <br> false: the String doesn't exists in the list.
get(int index) | index: index to return | String | returns the String from the specifed index | get(int index) | index: index to return | String | returns the String from the specifed index <br> retruns an empty String if index is out of bounds |
indexOf(String s) | s: String to search | int | Returns the index of the first eaqual String in this list, or -1 if this list does not contain the element. | indexOf(String s) | s: String to search | int | Returns the index of the first eaqual String in this list, or -1 if this list does not contain the element. |
isEmpty() | | Boolean | Returns true if the list contains no elements. | isEmpty() | | Boolean | Returns true if the list contains no elements. |
remove(int index) | index: index to remove | String | removes the specified index and returns the removed String. remove(int index) | index: index to remove | String | removes the specified index and returns the removed String. <br> returns empty String if the index is out of bounds and doesn't remove anything
set(int index, String s) | index: index to replace <br> s: String to replace with. | Boolean | Replaces the String at the specified position in this list with the specified String. | set(int index, String s) | index: index to replace <br> s: String to replace with. | Boolean | Replaces the String at the specified position in this list with the specified String. <br> returns false if index is out of bounds and does nothing else true |
size() | | int | Returns the number of elements in this list. size() | | int | Returns the number of elements in this list.
toArray() | | String[] | Returns an array containing all Strings in this list in proper sequence (from first to last String). The returned Array is a deep copy. This means that if you change a String in the returned Array the String isn't changed in this list. toArray() | | String[] | Returns an array containing all Strings in this list in proper sequence (from first to last String). The returned Array is a deep copy. This means that if you change a String in the returned Array the String isn't changed in this list

View File

@ -11,6 +11,7 @@ class MeineArrayList_Test {
MeineArrayList list = new MeineArrayList(); MeineArrayList list = new MeineArrayList();
list.add("Test"); list.add("Test");
assertEquals("Test", list.get(0)); assertEquals("Test", list.get(0));
assertEquals("", list.get(10));
} }
@Test @Test
@ -22,12 +23,11 @@ class MeineArrayList_Test {
assertEquals("Test2", list.get(1)); assertEquals("Test2", list.get(1));
list.add("Test3"); list.add("Test3");
assertEquals("Test3", list.get(2)); assertEquals("Test3", list.get(2));
list.add(0, "Test4"); assertTrue(list.add(0, "Test4"));
assertEquals("Test4", list.get(0)); assertEquals("Test4", list.get(0));
list.add(4, "Test5"); assertTrue(list.add(4, "Test5"));
assertEquals("Test5", list.get(4)); assertEquals("Test5", list.get(4));
assertFalse(list.add(10,"testw3")); assertFalse(list.add(10,"testw3"));
assertTrue(list.add(0,"testw3"));
} }
@Test @Test
@ -51,7 +51,7 @@ class MeineArrayList_Test {
assertEquals("2", liste1.get(5)); assertEquals("2", liste1.get(5));
assertEquals("3", liste1.get(6)); assertEquals("3", liste1.get(6));
assertEquals("4", liste1.get(7)); assertEquals("4", liste1.get(7));
liste1.addAll(1,liste2); assertTrue(liste1.addAll(1,liste2));
assertEquals("1", liste1.get(0)); assertEquals("1", liste1.get(0));
assertEquals("1", liste1.get(1)); assertEquals("1", liste1.get(1));
assertEquals("2", liste1.get(2)); assertEquals("2", liste1.get(2));
@ -64,6 +64,7 @@ class MeineArrayList_Test {
assertEquals("2", liste1.get(9)); assertEquals("2", liste1.get(9));
assertEquals("3", liste1.get(10)); assertEquals("3", liste1.get(10));
assertEquals("4", liste1.get(11)); assertEquals("4", liste1.get(11));
assertFalse(liste1.addAll(100,liste2));
} }
@Test @Test
@ -116,6 +117,7 @@ class MeineArrayList_Test {
assertEquals("2", list.remove(0)); assertEquals("2", list.remove(0));
assertEquals("3", list.remove(0)); assertEquals("3", list.remove(0));
assertEquals("4", list.remove(0)); assertEquals("4", list.remove(0));
assertEquals("", list.remove(0));
} }
@Test @Test
@ -156,5 +158,9 @@ class MeineArrayList_Test {
assertArrayEquals(new String[] {"1","2","3"}, list.toArray()); assertArrayEquals(new String[] {"1","2","3"}, list.toArray());
list.add("4"); list.add("4");
assertArrayEquals(new String[] {"1","2","3","4"}, list.toArray()); assertArrayEquals(new String[] {"1","2","3","4"}, list.toArray());
String[] tmparr = list.toArray();
tmparr[0] = "test";
assertEquals("test", tmparr[0]);
assertEquals("1", list.get(0));
} }
} }