Praktikum 3: Tests
This commit is contained in:
parent
f2929c42ff
commit
2612ab664d
|
@ -43,6 +43,7 @@ public class Vorlesungsverzeichnis {
|
|||
for(String name:s) {
|
||||
list.remove(name);
|
||||
}
|
||||
Collections.sort(list);
|
||||
return new HashSet<>(list);
|
||||
}
|
||||
|
||||
|
@ -59,6 +60,7 @@ public class Vorlesungsverzeichnis {
|
|||
list.add(v.getTitle());
|
||||
}
|
||||
}
|
||||
Collections.sort(list);
|
||||
map.put(gruppe, list);
|
||||
list = new ArrayList<>();
|
||||
}
|
||||
|
|
|
@ -1,17 +1,29 @@
|
|||
package de.joethei.hs.java2.tests;
|
||||
|
||||
import de.joethei.hs.java2.praktikum.praktikum3.Vorlesungsverzeichnis;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.*;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
|
||||
public class VorlesungsverzeichnisTest {
|
||||
|
||||
private Vorlesungsverzeichnis vorlesungsverzeichnis;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
try {
|
||||
vorlesungsverzeichnis = new Vorlesungsverzeichnis(Objects.requireNonNull(getClass().getClassLoader().getResource("vorlesungen.txt")).getFile());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test(expected = IOException.class)
|
||||
public void constructors() throws IOException {
|
||||
new Vorlesungsverzeichnis("HalloWelt");
|
||||
|
@ -19,8 +31,6 @@ public class VorlesungsverzeichnisTest {
|
|||
|
||||
@Test
|
||||
public void titles() {
|
||||
try {
|
||||
Vorlesungsverzeichnis vorlesungsverzeichnis = new Vorlesungsverzeichnis(Objects.requireNonNull(getClass().getClassLoader().getResource("vorlesungen.txt")).getFile());
|
||||
List<String> titles = new ArrayList<>();
|
||||
titles.add("Algorithmen und Datenstrukturen");
|
||||
titles.add("Audio-/Videotechnik");
|
||||
|
@ -33,11 +43,61 @@ public class VorlesungsverzeichnisTest {
|
|||
|
||||
titles.add("Hallo Welt");
|
||||
assertNotEquals(vorlesungsverzeichnis.titles(), titles);
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void workaholics() {
|
||||
Set<String> set = new HashSet<>();
|
||||
set.add("von Coelln");
|
||||
assertEquals(vorlesungsverzeichnis.workaholics(), set);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void groupToTitles() {
|
||||
Map<String, List<String>> map = vorlesungsverzeichnis.groupToTitles();
|
||||
|
||||
List<String> mt2 = new ArrayList<>();
|
||||
mt2.add("Audio-/Videotechnik");
|
||||
mt2.add("Mathematik 2");
|
||||
|
||||
List<String> e2 = new ArrayList<>();
|
||||
e2.add("Mathematik 2");
|
||||
|
||||
List<String> i2 = new ArrayList<>();
|
||||
i2.add("Algorithmen und Datenstrukturen");
|
||||
i2.add("Java 2");
|
||||
|
||||
List<String> i4 = new ArrayList<>();
|
||||
i4.add("Rechnerarchitekturen");
|
||||
|
||||
assertEquals(mt2, map.get("MT2"));
|
||||
assertEquals(e2, map.get("E2"));
|
||||
assertEquals(i2, map.get("I2"));
|
||||
assertEquals(i4, map.get("I4"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipleTitles() {
|
||||
Map<String, List<String>> map = vorlesungsverzeichnis.multipleTitles();
|
||||
|
||||
List<String> math = new ArrayList<>();
|
||||
math.add("von Coelln");
|
||||
math.add("Rabe");
|
||||
|
||||
assertEquals(map.get("Mathematik 2"), math);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void descendingTitles() {
|
||||
List<String> list = new ArrayList<>();
|
||||
list.add("Java 2");
|
||||
list.add("Algorithmen und Datenstrukturen");
|
||||
list.add("Mathematik 2");
|
||||
list.add("Mathematik 2");
|
||||
list.add("Audio-/Videotechnik");
|
||||
list.add("Rechnerarchitekturen");
|
||||
|
||||
assertEquals(list, vorlesungsverzeichnis.descendingTitles());
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue