Testat Sammlung
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

137 lines
2.4 KiB

package solution;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
public abstract class SimpleListTest90 {
ISimpleList<String> list;
protected String nodeNull = null;
protected String node0 = "0";
protected String node1 = "1";
protected String node2 = "2";
protected String node3 = "3";
protected String node4 = "4";
protected abstract ISimpleList<String> getInstance1();
protected void add2() {
list.add(node1);
list.add(node2);
}
@BeforeAll
static void setUpBeforeClass() throws Exception {
}
@BeforeEach
void setUp() throws Exception {
list = getInstance1();
}
@Test
public void testAdd1() {
boolean actual = list.add(node1);
assertEquals(true, actual);
}
@Test
public void testAdd2() {
add2();
list.remove(node2);
list.add(node3);
list.add(node4);
String actual = list.get(2);
assertEquals(node3, actual);
}
@Test
public void testRemoveObject() {
list.add(node1);
list.add(node2);
list.add(node3);
boolean actual = list.remove(node2);
assertEquals(true, actual);
}
@Test
public void testRemoveSize() {
add2();
list.remove(1);
int actual = list.size();
assertEquals(1, actual);
}
@Test
public void testContainsTrue() {
add2();
boolean actual = list.contains(node1);
assertEquals(true, actual);
}
@Test
public void testContainsFalse() {
add2();
boolean actual = list.contains(node3);
assertEquals(false, actual);
}
@Test
public void testForAll1() {
list.forAll(null);
assertEquals(true, true);
}
@Test
public void getNodeIndex() {
add2();
String actual = list.get(1);
assertEquals(node2, actual);
}
@Test
public void setNodeIndex() {
add2();
list.set(1, node3);
String actual = list.get(1);
assertEquals(node3, actual);
}
@Test
public void testRemoveIndex() {
add2();
list.add(node3);
boolean actual = list.remove(1);
assertEquals(true, actual);
}
@Test
public void testAddIndexException() {
try {
list.add(-1, node1);
list.get(0);
} catch (Exception e) {
assertEquals(true, e instanceof IndexOutOfBoundsException);
}
}
@Test
public void testAddIndexSameSize() {
add2();
list.add(2, node4);
String actual = list.get(2);
assertEquals(node4, actual);
}
@Test
public void testAddIndexNewNode() {
add2();
list.add(1, node3);
String actual = list.get(1);
assertEquals(node3, actual);
}
}