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.
243 lines
4.6 KiB
243 lines
4.6 KiB
package testat;
|
|
|
|
import org.junit.jupiter.api.BeforeAll;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
import java.util.function.Consumer;
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
import testat.ISimpleMap;
|
|
|
|
public abstract class ASimpleMapTest {
|
|
|
|
ISimpleMap<String, String> map;
|
|
|
|
protected abstract ISimpleMap<String, String> getInstance();
|
|
|
|
private int counter = 0;
|
|
private String result;
|
|
|
|
Consumer<String> action = s -> {
|
|
counter++;
|
|
result = result + s;
|
|
};
|
|
|
|
@BeforeAll
|
|
static void setUpBeforeClass() throws Exception {
|
|
}
|
|
|
|
@BeforeEach
|
|
void setUp() throws Exception {
|
|
map = getInstance();
|
|
}
|
|
|
|
@Test
|
|
void testadd1() {
|
|
String actual = map.put("1", "Hallo");
|
|
assertEquals(null, actual);
|
|
}
|
|
|
|
@Test
|
|
void testadd2a() {
|
|
String actual = map.put(null, "xxx");
|
|
assertEquals(null, actual);
|
|
}
|
|
|
|
@Test
|
|
void testadd2b() {
|
|
String actual = map.put("1", null);
|
|
assertEquals(null, actual);
|
|
}
|
|
|
|
@Test
|
|
void testadd3() {
|
|
add3();
|
|
String actual = map.put("1", "Hallo");
|
|
assertEquals("Eins", actual);
|
|
}
|
|
|
|
@Test
|
|
void testadd4() {
|
|
add3();
|
|
map.put("4", "Vier");
|
|
map.put("5", "F�nf");
|
|
map.remove("3");
|
|
map.put("6", "Sechs");
|
|
|
|
String actual = map.get("1");
|
|
assertEquals("Eins", actual);
|
|
actual = map.get("2");
|
|
assertEquals("Zwei", actual);
|
|
actual = map.get("4");
|
|
assertEquals("Vier", actual);
|
|
actual = map.get("5");
|
|
assertEquals("F�nf", actual);
|
|
actual = map.get("6");
|
|
assertEquals("Sechs", actual);
|
|
}
|
|
|
|
@Test
|
|
void testget1() {
|
|
String actual = map.get(null);
|
|
assertEquals(null, actual);
|
|
}
|
|
|
|
@Test
|
|
void testget2() {
|
|
String actual = map.get("1");
|
|
assertEquals(null, actual);
|
|
}
|
|
|
|
@Test
|
|
void testget3() {
|
|
add3();
|
|
String actual = map.get("1");
|
|
assertEquals("Eins", actual);
|
|
actual = map.get("2");
|
|
assertEquals("Zwei", actual);
|
|
actual = map.get("3");
|
|
assertEquals("Drei", actual);
|
|
}
|
|
|
|
@Test
|
|
void testremove1() {
|
|
String actual = map.remove(null);
|
|
assertEquals(null, actual);
|
|
}
|
|
|
|
@Test
|
|
void testremove2() {
|
|
String actual = map.remove("1");
|
|
assertEquals(null, actual);
|
|
}
|
|
|
|
@Test
|
|
void testremove3() {
|
|
add3();
|
|
String actual = map.remove(null);
|
|
assertEquals(null, actual);
|
|
}
|
|
|
|
@Test
|
|
void testremove4() {
|
|
add3();
|
|
String actual = map.remove("9");
|
|
assertEquals(null, actual);
|
|
}
|
|
|
|
@Test
|
|
void testremove5() {
|
|
add3();
|
|
String actual = map.remove("1");
|
|
assertEquals("Eins", actual);
|
|
actual = map.get("1");
|
|
assertEquals(null, actual);
|
|
actual = map.remove("2");
|
|
assertEquals("Zwei", actual);
|
|
actual = map.get("2");
|
|
assertEquals(null, actual);
|
|
actual = map.remove("3");
|
|
assertEquals("Drei", actual);
|
|
actual = map.get("3");
|
|
assertEquals(null, actual);
|
|
}
|
|
|
|
@Test
|
|
void testcontains1() {
|
|
Boolean actual = map.contains(null);
|
|
assertEquals(false, actual);
|
|
}
|
|
|
|
@Test
|
|
void testcontains2() {
|
|
Boolean actual = map.contains("1");
|
|
assertEquals(false, actual);
|
|
}
|
|
|
|
@Test
|
|
void testcontains3() {
|
|
add3();
|
|
Boolean actual = map.contains("Eins");
|
|
assertEquals(true, actual);
|
|
actual = map.contains("Zwei");
|
|
assertEquals(true, actual);
|
|
actual = map.contains("Drei");
|
|
assertEquals(true, actual);
|
|
actual = map.contains("xxx");
|
|
assertEquals(false, actual);
|
|
}
|
|
|
|
@Test
|
|
void testsize1() {
|
|
int actual = map.size();
|
|
assertEquals(0, actual);
|
|
}
|
|
|
|
@Test
|
|
void testsize2() {
|
|
add3();
|
|
int actual = map.size();
|
|
assertEquals(3, actual);
|
|
}
|
|
|
|
@Test
|
|
void testAddSize1() {
|
|
add3();
|
|
add3();
|
|
int actual = map.size();
|
|
assertEquals(3, actual);
|
|
}
|
|
|
|
@Test
|
|
void testRemoveSize1() {
|
|
add3();
|
|
map.remove("2");
|
|
int actual = map.size();
|
|
assertEquals(2, actual);
|
|
}
|
|
|
|
@Test
|
|
void testRemoveContains1() {
|
|
add3();
|
|
map.remove("2");
|
|
Boolean actual = map.contains("Eins");
|
|
assertEquals(true, actual);
|
|
actual = map.contains("Zwei");
|
|
assertEquals(false, actual);
|
|
actual = map.contains("Drei");
|
|
assertEquals(true, actual);
|
|
actual = map.contains("xxx");
|
|
assertEquals(false, actual);
|
|
}
|
|
|
|
@Test
|
|
void testForAll1() {
|
|
map.forEach(null);
|
|
assertEquals(true, true);
|
|
}
|
|
|
|
@Test
|
|
void testForAll2() {
|
|
map.forEach(action);
|
|
assertEquals(true, true);
|
|
}
|
|
|
|
@Test
|
|
void testForAll3() {
|
|
add3();
|
|
counter = 0;
|
|
result = new String("");
|
|
map.forEach(action);
|
|
assertEquals(3, counter);
|
|
assertEquals(true, result.contains("Eins"));
|
|
assertEquals(true, result.contains("Zwei"));
|
|
assertEquals(true, result.contains("Drei"));
|
|
}
|
|
|
|
protected void add3() {
|
|
map.put("1", "Eins");
|
|
map.put("2", "Zwei");
|
|
map.put("3", "Drei");
|
|
}
|
|
}
|
|
|