Praktikum 3: offizielle Testklasse
This commit is contained in:
parent
a1b1e0b9c7
commit
735435382b
@ -13,7 +13,11 @@ public class Vorlesung {
|
||||
this.studiengruppe = list.get(0);
|
||||
this.title = list.get(1);
|
||||
this.dozent = list.get(2);
|
||||
this.teilnehmerzahl = Integer.parseInt(list.get(3));
|
||||
try {
|
||||
this.teilnehmerzahl = Integer.parseInt(list.get(3));
|
||||
}catch (NumberFormatException ex) {
|
||||
throw new TextFileFormatException("Input is no number");
|
||||
}
|
||||
}
|
||||
|
||||
public String getStudiengruppe() {
|
||||
|
@ -39,8 +39,10 @@ public class Vorlesungsverzeichnis implements Comparator<Vorlesung>{
|
||||
* @return eine alphabetisch sortierte Liste mit den Titeln aller Vorlesungen.
|
||||
*/
|
||||
public List<String> titles() {
|
||||
List<String> list = new ArrayList<>();
|
||||
vorlesungen.forEach(vorlesung -> list.add(vorlesung.getTitle()));
|
||||
Set<String> set = new HashSet<>();
|
||||
vorlesungen.forEach(vorlesung -> set.add(vorlesung.getTitle()));
|
||||
|
||||
List<String> list = new ArrayList<>(set);
|
||||
Collections.sort(list);
|
||||
return list;
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ public class VorlesungsverzeichnisTest {
|
||||
new Vorlesungsverzeichnis(Objects.requireNonNull(getClass().getClassLoader().getResource("praktikum3/vorlesungen-format.txt")).getFile());
|
||||
}
|
||||
|
||||
@Test(expected = NumberFormatException.class)
|
||||
@Test(expected = TextFileFormatException.class)
|
||||
public void constructorNumberFormatException() throws IOException, TextFileFormatException {
|
||||
new Vorlesungsverzeichnis(Objects.requireNonNull(getClass().getClassLoader().getResource("praktikum3/vorlesungen-number.txt")).getFile());
|
||||
}
|
||||
@ -49,7 +49,6 @@ public class VorlesungsverzeichnisTest {
|
||||
titles.add("Internet-Technologien");
|
||||
titles.add("Java 2");
|
||||
titles.add("Mathematik 2");
|
||||
titles.add("Mathematik 2");
|
||||
titles.add("Rechnerarchitekturen");
|
||||
|
||||
assertEquals(vorlesungsverzeichnis.titles(), titles);
|
||||
|
@ -0,0 +1,240 @@
|
||||
package de.joethei.hs.java2.tests;
|
||||
|
||||
import de.joethei.hs.java2.praktikum.praktikum3.TextFileFormatException;
|
||||
import de.joethei.hs.java2.praktikum.praktikum3.Vorlesung;
|
||||
import de.joethei.hs.java2.praktikum.praktikum3.Vorlesungsverzeichnis;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.*;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class VorlesungsverzeichnisTest2 {
|
||||
String filename = "db_junit.txt";
|
||||
PrintWriter pw;
|
||||
|
||||
Class<Vorlesung> c = Vorlesung.class; // Klasse Vorlesung vorhanden?
|
||||
|
||||
@Before
|
||||
public void setUp() throws IOException
|
||||
{
|
||||
pw = new PrintWriter(filename);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void Titles() throws IOException, TextFileFormatException
|
||||
{
|
||||
List<String> al = new ArrayList<>();
|
||||
|
||||
al.add("Elektrodynamik");
|
||||
al.add("Quantenmechanik");
|
||||
al.add("Quantenphysik");
|
||||
al.add("Relativitätstheorie");
|
||||
al.add("Theoretische Physik");
|
||||
al.add("Thermodynamik");
|
||||
|
||||
pw.print(
|
||||
"A1:Relativitätstheorie:Einstein:15\n" +
|
||||
"B2:Quantenmechanik:Heisenberg:17\n" +
|
||||
"C2:Quantenphysik:Planck:5\n" +
|
||||
"T4:Thermodynamik:Kelvin:78\n" +
|
||||
"C2:Theoretische Physik:Kelvin:54\n" +
|
||||
"B2:Thermodynamik:Planck:44\n" +
|
||||
"T4:Quantenphysik:Planck:45\n" +
|
||||
"B2:Elektrodynamik:Kelvin:34");
|
||||
pw.close();
|
||||
|
||||
|
||||
Vorlesungsverzeichnis l = new Vorlesungsverzeichnis(filename);
|
||||
// System.out.println(al);
|
||||
// System.out.println(l.titles());
|
||||
assertEquals(al,l.titles());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void Workaholics() throws IOException, TextFileFormatException
|
||||
{
|
||||
Set<String> s = new HashSet<>();
|
||||
|
||||
s.add("Planck");
|
||||
s.add("Kelvin");
|
||||
|
||||
pw.print(
|
||||
"A1:Relativitätstheorie:Einstein:15\n" +
|
||||
"B2:Quantenmechanik:Heisenberg:17\n" +
|
||||
"C2:Quantenphysik:Planck:5\n" +
|
||||
"T4:Thermodynamik:Kelvin:78\n" +
|
||||
"C2:Theoretische Physik:Kelvin:54\n" +
|
||||
"B2:Thermodynamik:Planck:44\n" +
|
||||
"T4:Quantenphysik:Planck:45\n" +
|
||||
"B2:Elektrodynamik:Kelvin:34");
|
||||
pw.close();
|
||||
|
||||
|
||||
Vorlesungsverzeichnis l = new Vorlesungsverzeichnis(filename);
|
||||
// System.out.println(s);
|
||||
// System.out.println(l.workaholics());
|
||||
assertEquals(s,l.workaholics());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void GroupToTitles() throws IOException, TextFileFormatException
|
||||
{
|
||||
Map<String, List<String>> map2 = new HashMap<>();
|
||||
List<String> s1 = new ArrayList<>();
|
||||
List<String> s2 = new ArrayList<>();
|
||||
List<String> s3a = new ArrayList<>();
|
||||
List<String> s3b = new ArrayList<>();
|
||||
List<String> s4a = new ArrayList<>();
|
||||
List<String> s4b = new ArrayList<>();
|
||||
|
||||
s1.add("Relativitätstheorie");
|
||||
map2.put("A1",s1);
|
||||
s2.add("Quantenmechanik");
|
||||
s2.add("Thermodynamik");
|
||||
s2.add("Elektrodynamik");
|
||||
map2.put("B2",s2);
|
||||
s3a.add("Quantenphysik");
|
||||
s3a.add("Theoretische Physik");
|
||||
s3b.add("Theoretische Physik");
|
||||
s3b.add("Quantenphysik");
|
||||
map2.put("C2",s3a);
|
||||
s4a.add("Thermodynamik");
|
||||
s4a.add("Quantenphysik");
|
||||
map2.put("T4",s4a);
|
||||
s4b.add("Quantenphysik");
|
||||
s4b.add("Thermodynamik");
|
||||
|
||||
pw.print(
|
||||
"A1:Relativitätstheorie:Einstein:15\n" +
|
||||
"B2:Quantenmechanik:Heisenberg:17\n" +
|
||||
"C2:Quantenphysik:Planck:5\n" +
|
||||
"T4:Thermodynamik:Kelvin:78\n" +
|
||||
"C2:Theoretische Physik:Kelvin:54\n" +
|
||||
"B2:Thermodynamik:Planck:44\n" +
|
||||
"T4:Quantenphysik:Planck:45\n" +
|
||||
"B2:Elektrodynamik:Kelvin:34");
|
||||
pw.close();
|
||||
|
||||
Vorlesungsverzeichnis l = new Vorlesungsverzeichnis(filename);
|
||||
// System.out.println(map2);
|
||||
// System.out.println(l.groupToTitles());
|
||||
// assertEquals(map2,l.groupToTitles());
|
||||
assertEquals(s1, l.groupToTitles().get("A1"));
|
||||
assertTrue(s3a.equals(l.groupToTitles().get("C2")) || s3b.equals(l.groupToTitles().get("C2")));
|
||||
assertTrue(s4a.equals(l.groupToTitles().get("T4")) || s4b.equals(l.groupToTitles().get("T4")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipleTitles() throws IOException, TextFileFormatException
|
||||
{
|
||||
Map<String, List<String>> map2 = new HashMap<>();
|
||||
List<String> s1a = new ArrayList<>();
|
||||
List<String> s1b = new ArrayList<>();
|
||||
|
||||
s1a.add("Kelvin");
|
||||
s1a.add("Planck");
|
||||
s1b.add("Planck");
|
||||
s1b.add("Kelvin");
|
||||
map2.put("Thermodynamik",s1a);
|
||||
|
||||
pw.print(
|
||||
"A1:Relativitätstheorie:Einstein:15\n" +
|
||||
"B2:Quantenmechanik:Heisenberg:17\n" +
|
||||
"C2:Quantenphysik:Planck:5\n" +
|
||||
"T4:Thermodynamik:Kelvin:78\n" +
|
||||
"C2:Theoretische Physik:Kelvin:54\n" +
|
||||
"B2:Thermodynamik:Planck:44\n" +
|
||||
"T4:Quantenphysik:Planck:45\n" +
|
||||
"B2:Elektrodynamik:Kelvin:34");
|
||||
pw.close();
|
||||
|
||||
|
||||
Vorlesungsverzeichnis l = new Vorlesungsverzeichnis(filename);
|
||||
// System.out.println(map2);
|
||||
// System.out.println(l.multipleTitles());
|
||||
// assertEquals(map2,l.multipleTitles());
|
||||
assertTrue(s1a.equals(l.multipleTitles().get("Thermodynamik")) || s1b.equals(l.multipleTitles().get("Thermodynamik")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void descendingTitles() throws IOException, TextFileFormatException
|
||||
{
|
||||
{
|
||||
List<String> al = new ArrayList<>();
|
||||
|
||||
al.add("Thermodynamik");
|
||||
al.add("Theoretische Physik");
|
||||
al.add("Quantenphysik");
|
||||
al.add("Thermodynamik");
|
||||
al.add("Elektrodynamik");
|
||||
al.add("Quantenmechanik");
|
||||
al.add("Relativitätstheorie");
|
||||
al.add("Quantenphysik");
|
||||
|
||||
pw.print(
|
||||
"A1:Relativitätstheorie:Einstein:15\n" +
|
||||
"B2:Quantenmechanik:Heisenberg:17\n" +
|
||||
"C2:Quantenphysik:Planck:5\n" +
|
||||
"T4:Thermodynamik:Kelvin:78\n" +
|
||||
"C2:Theoretische Physik:Kelvin:54\n" +
|
||||
"B2:Thermodynamik:Planck:44\n" +
|
||||
"T4:Quantenphysik:Planck:45\n" +
|
||||
"B2:Elektrodynamik:Kelvin:34");
|
||||
pw.close();
|
||||
|
||||
Vorlesungsverzeichnis l = new Vorlesungsverzeichnis(filename);
|
||||
// System.out.println(al);
|
||||
// System.out.println(l.descendingTitles());
|
||||
assertEquals(al,l.descendingTitles());
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected=TextFileFormatException.class)
|
||||
public void Liste_zu_kurz() throws IOException, TextFileFormatException {
|
||||
pw.print(
|
||||
"C2:Theoretische Physik:Kelvin:54\n" +
|
||||
"B2:Thermodynamik:Planck\n" +
|
||||
"T4:Quantenphysik:Planck:45\n" +
|
||||
"B2:Elektrodynamik:Kelvin:34");
|
||||
pw.close();
|
||||
Vorlesungsverzeichnis k = new Vorlesungsverzeichnis(filename);
|
||||
}
|
||||
|
||||
@Test(expected=TextFileFormatException.class)
|
||||
public void Liste_zu_lang() throws IOException, TextFileFormatException {
|
||||
pw.print(
|
||||
"C2:Theoretische Physik:Kelvin:54:55\n" +
|
||||
"B2:Thermodynamik:Planck:44\n" +
|
||||
"T4:Quantenphysik:Planck:45\n" +
|
||||
"B2:Elektrodynamik:Kelvin:34");
|
||||
pw.close();
|
||||
Vorlesungsverzeichnis k = new Vorlesungsverzeichnis(filename);
|
||||
}
|
||||
|
||||
@Test(expected=TextFileFormatException.class)
|
||||
public void Listenfeld_leer() throws IOException, TextFileFormatException {
|
||||
pw.print(
|
||||
"C2:Theoretische Physik:Kelvin:54\n" +
|
||||
"B2:Thermodynamik:Planck:44\n" +
|
||||
":Quantenphysik:Planck:45\n" +
|
||||
"B2:Elektrodynamik:Kelvin:34");
|
||||
pw.close();
|
||||
Vorlesungsverzeichnis k = new Vorlesungsverzeichnis(filename);
|
||||
}
|
||||
|
||||
@Test(expected=TextFileFormatException.class)
|
||||
public void Teilnehmerzahl_keine_Zahl() throws IOException, TextFileFormatException {
|
||||
pw.print(
|
||||
"C2:Theoretische Physik:Kelvin:54\n" +
|
||||
"B2:Thermodynamik:Planck:44\n" +
|
||||
"T4:Quantenphysik:Planck:45\n" +
|
||||
"B2:Elektrodynamik:Kelvin:ABC");
|
||||
pw.close();
|
||||
Vorlesungsverzeichnis k = new Vorlesungsverzeichnis(filename);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user