Java_2/src/test/java/de/joethei/hs/java2/tests/VorlesungsverzeichnisTest2....

241 lines
9.0 KiB
Java

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 {
private String filename = "src/main/resources/praktikum3/vorlesungen-db.txt";
private 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);
}
}