Compare commits

...

3 Commits

Author SHA1 Message Date
93fb940a8c refactor 2024-06-14 01:13:30 +02:00
55e6561e02 ich komm nicht mehr weiter 2024-06-14 01:12:27 +02:00
7972c9088c refactor 2024-06-14 01:03:45 +02:00
74 changed files with 195 additions and 4929 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,168 +0,0 @@
package oop.ch03.chess;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import static org.junit.Assert.assertEquals;
public class ChessTest {
// Das Zeilenende wird auf Windows-Systemen anders codiert als auf Nicht-Windows-Systemen.
// Die folgende Zeile ermittelt die aktuelle Codierung.
// EOL = "End of Line"
private static final String LS = System.lineSeparator();
private static final String HE = " 1 2 3 4 5 6 7 8" + LS;
private static final String LI = " +---+---+---+---+---+---+---+---+" + LS;
private static final String EMP = " | | | | | | | | |" + LS;
private static final String WK1 = " | n | | | | | | | |" + LS;
private static final String WQ3 = " | | | q | | | | | |" + LS;
private static final String CO1 = " | | | n | | N | Q | | |" + LS;
private static final String INIT_BOARD = board(EMP, EMP, EMP, EMP, EMP, EMP, EMP, EMP);
private static final String WK61_BOARD = board(EMP, EMP, EMP, EMP, EMP, WK1, EMP, EMP);
private static final String APP1_BOARD = board(EMP, EMP, EMP, EMP, WQ3, CO1, EMP, EMP);
private static final String CHECK_TEXT1 = "white queen at (4, 2)" + LS +
" cannot capture black queen at (8, 6)" + LS +
" cannot capture white knight at (6, 4)" + LS +
"black queen at (8, 6)" + LS +
" cannot capture white queen at (4, 2)" + LS +
" can capture white knight at (6, 4)" + LS +
"white knight at (6, 4)" + LS +
" cannot capture white queen at (4, 2)" + LS +
" cannot capture black queen at (8, 6)" + LS;
private static final String CHECK_TEXT2 = "white knight at (6, 3)" + LS +
" cannot capture black knight at (6, 5)" + LS +
" cannot capture black queen at (6, 6)" + LS +
" cannot capture white queen at (5, 3)" + LS +
"black knight at (6, 5)" + LS +
" cannot capture white knight at (6, 3)" + LS +
" cannot capture black queen at (6, 6)" + LS +
" can capture white queen at (5, 3)" + LS +
"black queen at (6, 6)" + LS +
" cannot capture white knight at (6, 3)" + LS +
" cannot capture black knight at (6, 5)" + LS +
" cannot capture white queen at (5, 3)" + LS +
"white queen at (5, 3)" + LS +
" cannot capture white knight at (6, 3)" + LS +
" cannot capture black knight at (6, 5)" + LS +
" cannot capture black queen at (6, 6)" + LS;
private static String board(String... s) {
if (s.length != 8)
throw new IllegalArgumentException("Expected 8, but got " + s.length + " arguments");
StringBuilder sb = new StringBuilder();
sb.append(HE).append(LI);
for (int i = 1; i <= 8; i++)
sb.append(i).append(s[i - 1]).append(LI);
return sb.toString();
}
private Board board;
private final ByteArrayOutputStream printed = new ByteArrayOutputStream();
private final PrintStream printStream = new PrintStream(printed, true);
@Before
public void setup() {
board = new Board();
printed.reset();
System.setOut(printStream);
}
@After
public void tearDown() {
printStream.close();
}
@Test
public void testEmpty() {
board.printBoard();
assertEquals(INIT_BOARD, printed.toString());
}
@Test(expected = IllegalArgumentException.class)
public void testInvalidPos1() {
new Knight(Color.white, board, 0, 4);
}
@Test(expected = IllegalArgumentException.class)
public void testInvalidPos2() {
new Queen(Color.white, board, 0, 4);
}
@Test
public void testWhiteknight() {
final Piece knight = new Knight(Color.white, board, 6, 1);
checkPieces(1);
assertEquals(knight, board.pieceAt(6, 1));
board.printBoard();
assertEquals(WK61_BOARD, printed.toString());
}
@Test
public void test3Pieces() {
final Piece queen1 = new Queen(Color.white, board, 4, 2);
final Piece queen2 = new Queen(Color.black, board, 8, 6);
final Piece knight = new Knight(Color.white, board, 6, 4);
Assert.assertFalse(queen1.canCapture(queen2));
Assert.assertFalse(queen1.canCapture(knight));
Assert.assertFalse(queen2.canCapture(queen1));
Assert.assertTrue(queen2.canCapture(knight));
Assert.assertFalse(knight.canCapture(queen1));
Assert.assertFalse(knight.canCapture(queen2));
checkPieces(3);
assertEquals(queen1, board.pieceAt(4, 2));
assertEquals(queen2, board.pieceAt(8, 6));
assertEquals(knight, board.pieceAt(6, 4));
board.check();
assertEquals(CHECK_TEXT1, printed.toString());
}
@Test
public void test4Pieces() {
final Piece knight1 = new Knight(Color.white, board, 6, 3);
final Piece knight2 = new Knight(Color.black, board, 6, 5);
final Piece queen1 = new Queen(Color.black, board, 6, 6);
final Piece queen2 = new Queen(Color.white, board, 5, 3);
checkPieces(4);
assertEquals(knight1, board.pieceAt(6, 3));
assertEquals(knight2, board.pieceAt(6, 5));
assertEquals(queen1, board.pieceAt(6, 6));
assertEquals(queen2, board.pieceAt(5, 3));
board.printBoard();
assertEquals(APP1_BOARD, printed.toString());
Assert.assertFalse(knight1.canCapture(knight2));
Assert.assertFalse(knight1.canCapture(queen1));
Assert.assertFalse(knight1.canCapture(queen2));
Assert.assertFalse(knight2.canCapture(knight1));
Assert.assertFalse(knight2.canCapture(queen1));
Assert.assertTrue(knight2.canCapture(queen2));
Assert.assertFalse(queen1.canCapture(knight1));
Assert.assertFalse(queen1.canCapture(knight2));
Assert.assertFalse(queen1.canCapture(queen2));
Assert.assertFalse(queen2.canCapture(knight1));
Assert.assertFalse(queen2.canCapture(knight2));
Assert.assertFalse(queen2.canCapture(queen1));
printed.reset();
board.check();
assertEquals(CHECK_TEXT2, printed.toString());
}
private void checkPieces(int expectedNumPieces) {
int numPieces = 0;
for (int row = 1; row < 9; row++)
for (int col = 1; col < 9; col++)
if (board.pieceAt(row, col) != null)
numPieces++;
assertEquals(expectedNumPieces, numPieces);
}
@Test
public void testRunWithErrors() {
final Piece rook = new Rook(Color.white, board, 1, 1);
assertEquals(rook, board.pieceAt(1, 1));
}
}

View File

@ -1,80 +0,0 @@
package oop.ch05.generic.mensa;
import oop.ch05.generic.secured.AuthorizationException;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;
public class MensaTest {
private static final String CONF_ACCOUNT = "33-1298";
private static final String OTHER_ACCOUNT = "33-1299";
private AccountManagement accountMgt;
private VendingMachine vm1;
private VendingMachine vm2;
private VendingMachine tumVM;
private CashPoint unibwMensa;
private AccountCard conf;
private MensaCard frankSmith;
private CashCard hansMueller;
private CashCard peterSchmidt;
private CashCard thomasMayer;
@Before
public void setup() {
accountMgt = new AccountManagement(4711, "UniBw admin");
vm1 = new VendingMachine("left", 4711);
vm2 = new VendingMachine("right", 4711);
tumVM = new VendingMachine("TUM Mensa", 3141);
unibwMensa = new CashPoint("UniBw Mensa", 4711, accountMgt);
conf = new AccountCard("conference", CONF_ACCOUNT, 42);
frankSmith = new CountCard("Frank Smith", Color.gray);
hansMueller = new CashCard("Hans Müller", Color.green, 4711);
peterSchmidt = new CashCard("Peter Schmidt", Color.green, 4711);
thomasMayer = new CashCard("Thomas Mayer", Color.blue, 4711);
}
@Test
public void testPayment() throws AuthorizationException, RejectedException {
vm1.deposit(hansMueller, 10);
vm1.deposit(peterSchmidt, 5);
vm2.deposit(thomasMayer, 2);
assertThrows(AuthorizationException.class, () -> tumVM.deposit(hansMueller, 10));
assertEquals(15, vm1.getEuros());
assertEquals(2, vm2.getEuros());
assertEquals(0, tumVM.getEuros());
assertEquals(1000, hansMueller.getBalance());
assertEquals(500, peterSchmidt.getBalance());
assertEquals(200, thomasMayer.getBalance());
hansMueller.pass(unibwMensa);
assertEquals(733, hansMueller.getBalance());
assertEquals(1, unibwMensa.getCounter());
assertEquals(267, unibwMensa.getCents());
frankSmith.pass(unibwMensa);
assertEquals(0, accountMgt.getAmount(CONF_ACCOUNT));
assertThrows(RejectedException.class, () -> conf.pass(unibwMensa));
assertThrows(RejectedException.class, () -> thomasMayer.pass(unibwMensa));
hansMueller.pass(unibwMensa);
hansMueller.pass(unibwMensa);
assertEquals(199, hansMueller.getBalance());
assertThrows(RejectedException.class, () -> hansMueller.pass(unibwMensa));
accountMgt.deposit(CONF_ACCOUNT, 1000);
accountMgt.deposit(OTHER_ACCOUNT, 2000);
assertEquals(100000, accountMgt.getAmount(CONF_ACCOUNT));
assertEquals(200000, accountMgt.getAmount(OTHER_ACCOUNT));
conf.pass(unibwMensa);
assertEquals(99505, accountMgt.getAmount(CONF_ACCOUNT));
assertEquals(200000, accountMgt.getAmount(OTHER_ACCOUNT));
assertEquals(5, unibwMensa.getCounter());
}
}

View File

@ -1,24 +0,0 @@
package oop.ch08.gui.mvc;
import oop.ch08.gui.mvc.model.CounterModel;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class TestModel {
@Test
public void testInitWithZero() {
final CounterModel model = new CounterModel();
assertEquals(0, model.getCounter());
}
@Test
public void testInc() {
final CounterModel model = new CounterModel();
int counter = model.getCounter();
model.increment();
assertEquals(++counter, model.getCounter());
model.increment();
assertEquals(++counter, model.getCounter());
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,280 +0,0 @@
package oop.ch09.calc.test;
import oop.ch06.calc.AdHocCalculator;
import oop.ch06.calc.Ops;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class AdHocCalculatorEdgeTest {
private AdHocCalculator calc;
@Before
public void setup() {
calc = new AdHocCalculator();
calc.digit(6);
calc.binOp(Ops.MULT);
calc.digit(7);
calc.eval();
}
@Test
public void test0() {
calc.clear();
assertEquals(0.0, calc.getValue(), 1e-20);
calc.digit(6);
assertEquals(6.0, calc.getValue(), 1e-10);
calc.digit(2);
assertEquals(62.0, calc.getValue(), 1e-10);
calc.dot();
assertEquals(62.0, calc.getValue(), 1e-10);
calc.clear();
assertEquals(0.0, calc.getValue(), 1e-20);
calc.unOp(Ops.EXP);
assertEquals(1.0, calc.getValue(), 1e-10);
calc.allClear();
assertEquals(0.0, calc.getValue(), 1e-20);
calc.binOp(Ops.MINUS);
assertEquals(0.0, calc.getValue(), 1e-10);
calc.eval();
assertEquals(0.0, calc.getValue(), 1e-10);
calc.eval();
assertEquals(0.0, calc.getValue(), 1e-10);
calc.dot();
assertEquals(0.0, calc.getValue(), 1e-10);
calc.allClear();
assertEquals(0.0, calc.getValue(), 1e-20);
}
@Test
public void test1() {
calc.binOp(Ops.DIV);
assertEquals(42.0, calc.getValue(), 1e-10);
calc.unOp(Ops.SQRT);
assertEquals(6.48074069840786, calc.getValue(), 1e-10);
calc.unOp(Ops.SQRT);
assertEquals(2.5457298950218306, calc.getValue(), 1e-10);
calc.digit(8);
assertEquals(8.0, calc.getValue(), 1e-10);
calc.eval();
assertEquals(5.25, calc.getValue(), 1e-10);
}
@Test
public void test2() {
calc.binOp(Ops.PLUS);
assertEquals(42.0, calc.getValue(), 1e-10);
calc.binOp(Ops.DIV);
assertEquals(42.0, calc.getValue(), 1e-10);
calc.dot();
assertEquals(0.0, calc.getValue(), 1e-10);
calc.allClear();
assertEquals(0.0, calc.getValue(), 1e-20);
}
@Test
public void test3() {
calc.binOp(Ops.MULT);
assertEquals(42.0, calc.getValue(), 1e-10);
calc.allClear();
assertEquals(0.0, calc.getValue(), 1e-20);
}
@Test
public void test4() {
calc.binOp(Ops.PLUS);
assertEquals(42.0, calc.getValue(), 1e-10);
calc.clear();
assertEquals(0.0, calc.getValue(), 1e-20);
calc.digit(5);
assertEquals(5.0, calc.getValue(), 1e-10);
calc.clear();
assertEquals(0.0, calc.getValue(), 1e-20);
}
@Test
public void test5() {
calc.digit(6);
assertEquals(6.0, calc.getValue(), 1e-10);
calc.allClear();
assertEquals(0.0, calc.getValue(), 1e-20);
}
@Test
public void test6() {
calc.digit(3);
assertEquals(3.0, calc.getValue(), 1e-10);
calc.binOp(Ops.DIV);
assertEquals(3.0, calc.getValue(), 1e-10);
}
@Test
public void test7() {
calc.digit(7);
assertEquals(7.0, calc.getValue(), 1e-10);
calc.clear();
assertEquals(0.0, calc.getValue(), 1e-20);
}
@Test
public void test8() {
calc.digit(9);
assertEquals(9.0, calc.getValue(), 1e-10);
calc.eval();
assertEquals(9.0, calc.getValue(), 1e-10);
}
@Test
public void test9() {
calc.digit(5);
assertEquals(5.0, calc.getValue(), 1e-10);
calc.unOp(Ops.CHANGE_SIGN);
assertEquals(-5.0, calc.getValue(), 1e-10);
}
@Test
public void test11() {
calc.dot();
assertEquals(0.0, calc.getValue(), 1e-10);
calc.binOp(Ops.PLUS);
assertEquals(0.0, calc.getValue(), 1e-10);
}
@Test
public void test12() {
calc.dot();
assertEquals(0.0, calc.getValue(), 1e-10);
calc.digit(2);
assertEquals(0.2, calc.getValue(), 1e-10);
calc.unOp(Ops.EXP);
assertEquals(1.2214027581601699, calc.getValue(), 1e-10);
}
@Test
public void test13() {
calc.dot();
assertEquals(0.0, calc.getValue(), 1e-10);
calc.eval();
assertEquals(0.0, calc.getValue(), 1e-10);
}
@Test
public void test14() {
calc.binOp(Ops.DIV);
assertEquals(42.0, calc.getValue(), 1e-10);
calc.unOp(Ops.SQRT);
assertEquals(6.48074069840786, calc.getValue(), 1e-10);
calc.clear();
assertEquals(0.0, calc.getValue(), 1e-20);
}
@Test
public void test15() {
calc.binOp(Ops.MINUS);
assertEquals(42.0, calc.getValue(), 1e-10);
calc.unOp(Ops.EXP);
assertEquals(1.73927494152050099E18, calc.getValue(), 1e-10);
calc.eval();
assertEquals(-1.73927494152050099E18, calc.getValue(), 1e-10);
}
@Test
public void test16() {
calc.binOp(Ops.MINUS);
assertEquals(42.0, calc.getValue(), 1e-10);
calc.unOp(Ops.EXP);
assertEquals(1.73927494152050099E18, calc.getValue(), 1e-10);
calc.binOp(Ops.MINUS);
assertEquals(-1.73927494152050099E18, calc.getValue(), 1e-10);
}
@Test
public void test17() {
calc.binOp(Ops.DIV);
assertEquals(42.0, calc.getValue(), 1e-10);
calc.unOp(Ops.EXP);
assertEquals(1.73927494152050099E18, calc.getValue(), 1e-10);
calc.allClear();
assertEquals(0.0, calc.getValue(), 1e-20);
}
@Test
public void test18() {
calc.binOp(Ops.DIV);
assertEquals(42.0, calc.getValue(), 1e-10);
calc.unOp(Ops.SQRT);
assertEquals(6.48074069840786, calc.getValue(), 1e-10);
calc.dot();
assertEquals(0.0, calc.getValue(), 1e-10);
calc.binOp(Ops.PLUS);
assertTrue(Double.isNaN(calc.getValue()));
}
@Test
public void test19() {
calc.binOp(Ops.DIV);
assertEquals(42.0, calc.getValue(), 1e-10);
calc.digit(2);
assertEquals(2.0, calc.getValue(), 1e-10);
calc.digit(5);
assertEquals(25.0, calc.getValue(), 1e-10);
calc.unOp(Ops.CHANGE_SIGN);
assertEquals(-25.0, calc.getValue(), 1e-10);
}
@Test
public void test20() {
calc.binOp(Ops.PLUS);
assertEquals(42.0, calc.getValue(), 1e-10);
calc.digit(9);
assertEquals(9.0, calc.getValue(), 1e-10);
calc.binOp(Ops.PLUS);
assertEquals(51.0, calc.getValue(), 1e-10);
}
@Test
public void test21() {
calc.binOp(Ops.MULT);
assertEquals(42.0, calc.getValue(), 1e-10);
calc.digit(7);
assertEquals(7.0, calc.getValue(), 1e-10);
calc.dot();
assertEquals(7.0, calc.getValue(), 1e-10);
calc.unOp(Ops.SQRT);
assertEquals(2.6457513110645907, calc.getValue(), 1e-10);
}
@Test
public void test22() {
calc.binOp(Ops.PLUS);
assertEquals(42.0, calc.getValue(), 1e-10);
calc.digit(3);
assertEquals(3.0, calc.getValue(), 1e-10);
calc.allClear();
assertEquals(0.0, calc.getValue(), 1e-20);
}
@Test
public void test23() {
calc.binOp(Ops.MULT);
assertEquals(42.0, calc.getValue(), 1e-10);
calc.dot();
assertEquals(0.0, calc.getValue(), 1e-10);
calc.digit(3);
assertEquals(0.3, calc.getValue(), 1e-10);
calc.clear();
assertEquals(0.0, calc.getValue(), 1e-20);
}
@Test
public void test24() {
calc.binOp(Ops.PLUS);
assertEquals(42.0, calc.getValue(), 1e-10);
calc.dot();
assertEquals(0.0, calc.getValue(), 1e-10);
calc.eval();
assertEquals(42.0, calc.getValue(), 1e-10);
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,34 +0,0 @@
package oop.ch09.testing;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
public class ExceptionTest {
@Test
public void testDivZero1() {
int zero = 0;
int result = 4 / zero;
assertTrue(true);
}
@Test
public void testDivZero2() {
int zero = 0;
try {
int result = 4 / zero;
fail("ArithmeticException kam nicht");
}
catch (ArithmeticException ex) {
assertEquals("/ by zero", ex.getMessage());
}
}
@Test(expected = ArithmeticException.class)
public void testDivZero2b() {
int zero = 0;
int result = 4 / zero;
}
}

View File

@ -1,134 +0,0 @@
package test.uebung.uebung04.tournament;
import org.junit.Before;
import org.junit.Test;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;
public class TournamentTest {
private static final String BORGHOFF = "Prof. Borghoff";
private static final String HOMMEL = "Prof. Hommel";
private static final String KOCH = "Prof. Koch";
private static final String MINAS = "Prof. Minas";
private static final String BUCHENRIEDER = "Prof. Buchenrieder";
private static final String DREO = "Prof. Dreo";
private static final String ROSE = "Prof. Rose";
private static final String SIEGLE = "Prof. Siegle";
private static final String TEEGE = "Prof. Teege";
private static final Set<String> SET1 = Set.of(BORGHOFF, HOMMEL, KOCH, MINAS, BUCHENRIEDER, DREO, ROSE, SIEGLE, TEEGE);
private static final Set<String> SET2 = Set.of(BORGHOFF, MINAS, SIEGLE, HOMMEL, DREO);
private static final Set<String> SET3 = Set.of(BORGHOFF, MINAS, SIEGLE);
private static final Set<String> SET4 = Set.of(MINAS, SIEGLE);
private static final Set<String> SET5 = Set.of(MINAS);
private Tournament tournament;
private Game r1s1;
private Game r1s2;
private Game r1s3;
private Game r1s4;
private Game r2s1;
private Game r2s2;
private Game r3s1;
private Game r4s1;
@Before
public void setup() {
r1s1 = new SeededGame(HOMMEL, KOCH);
r1s2 = new SeededGame(MINAS, BUCHENRIEDER);
r1s3 = new SeededGame(DREO, ROSE);
r1s4 = new SeededGame(SIEGLE, TEEGE);
r2s1 = new ByeGame(BORGHOFF, r1s1);
r2s2 = new OrdinaryGame(r1s2, r1s3);
r3s1 = new OrdinaryGame(r2s1, r2s2);
r4s1 = new OrdinaryGame(r3s1, r1s4);
tournament = new Tournament("UniBw Sportschießen", r4s1);
}
@Test
public void testBeforeFirstRound() {
assertEquals(SET1, asSet(tournament.getAllPlayers()));
assertEquals(SET1, asSet(tournament.getRemainingPlayers()));
}
@Test
public void testFirstRound() {
r1s1.setWinner(HOMMEL);
r1s2.setWinner(MINAS);
r1s3.setWinner(DREO);
r1s4.setWinner(SIEGLE);
assertEquals(SET1, asSet(tournament.getAllPlayers()));
assertEquals(SET2, asSet(tournament.getRemainingPlayers()));
}
@Test
public void testSecondRound() {
r1s1.setWinner(HOMMEL);
r1s2.setWinner(MINAS);
r1s3.setWinner(DREO);
r1s4.setWinner(SIEGLE);
r2s1.setWinner(BORGHOFF);
r2s2.setWinner(MINAS);
assertEquals(SET1, asSet(tournament.getAllPlayers()));
assertEquals(SET3, asSet(tournament.getRemainingPlayers()));
}
@Test
public void testThirdRound() {
r1s1.setWinner(HOMMEL);
r1s2.setWinner(MINAS);
r1s3.setWinner(DREO);
r1s4.setWinner(SIEGLE);
r2s1.setWinner(BORGHOFF);
r2s2.setWinner(MINAS);
r3s1.setWinner(MINAS);
assertEquals(SET1, asSet(tournament.getAllPlayers()));
assertEquals(SET4, asSet(tournament.getRemainingPlayers()));
}
@Test
public void testCompleteTournament() {
r1s1.setWinner(HOMMEL);
r1s2.setWinner(MINAS);
r1s3.setWinner(DREO);
r1s4.setWinner(SIEGLE);
r2s1.setWinner(BORGHOFF);
r2s2.setWinner(MINAS);
r3s1.setWinner(MINAS);
r4s1.setWinner(MINAS);
assertEquals(SET1, asSet(tournament.getAllPlayers()));
assertEquals(SET5, asSet(tournament.getRemainingPlayers()));
}
@Test
public void testException() {
r1s1.setWinner(HOMMEL);
r1s2.setWinner(MINAS);
r1s3.setWinner(DREO);
r1s4.setWinner(SIEGLE);
r2s1.setWinner(BORGHOFF);
r2s2.setWinner(MINAS);
r3s1.setWinner(MINAS);
assertThrows(IllegalArgumentException.class, () -> r4s1.setWinner(BUCHENRIEDER));
}
@Test(expected = IllegalStateException.class)
public void testException2() {
r4s1.setWinner(MINAS);
}
@Test
public void testException3() {
r1s1.setWinner(HOMMEL);
assertThrows(IllegalStateException.class, () -> r1s1.setWinner(HOMMEL));
}
private static <T> Set<T> asSet(Collection<T> collection) {
return new HashSet<>(collection);
}
}

View File

@ -1,13 +1,18 @@
package logistics; package test.uebung.uebung05.logistics;
import uebung05.logistics.Helicopter;
import uebung05.logistics.Manager;
import uebung05.logistics.Tank;
import uebung05.logistics.material.BulletBelts;
import uebung05.logistics.material.Grease;
import uebung05.logistics.material.LiterDiesel;
import uebung05.logistics.material.MetGallonsKerosene;
import uebung05.logistics.material.Oil;
import uebung05.logistics.material.RocketPods;
import uebung05.logistics.material.ShellBatches;
import uebung05.logistics.quantities.NeedCollector;
import logistics.material.BulletBelts;
import logistics.material.Grease;
import logistics.material.LiterDiesel;
import logistics.material.MetGallonsKerosene;
import logistics.material.Oil;
import logistics.material.RocketPods;
import logistics.material.ShellBatches;
import logistics.quantities.NeedCollector;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;

View File

@ -1,6 +1,8 @@
package test.uebung.uebung05.logistics.storage; package test.uebung.uebung05.logistics.storage;
import uebung05.*; import uebung05.logistics.material.Oil;
import uebung05.logistics.storage.IntStorage;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;

View File

@ -1,20 +1,26 @@
package uebung04; package uebung04;
import java.util.ArrayList;
public class ByeGame extends Game{ public class ByeGame extends Game{
private String player1; private String player1;
private String player2;
public ByeGame(String player1, Game player2){ public ByeGame(String player1, String player2){
this.player1 = player1; this.player1 = player1;
this.player2 = player2; this.player2 = player2;
} }
public String getPlayer1(){return player1;} public String getPlayer1(){return player1;}
public String getPlayer2(){return player2;}
public ??? getPlayer2(){ @Override
return player2.getAllPlayers(); public ArrayList<String> getAllPlayers() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'getAllPlayers'");
} }

View File

@ -7,7 +7,7 @@ public class OrdinaryGame extends Game{
private final int id; private final int id;
public OrdinaryGame(Game player1, Game player2){ public OrdinaryGame(String player1, String player2){
this.player1 = player1; this.player1 = player1;
this.player2 = player2; this.player2 = player2;
@ -15,18 +15,16 @@ public class OrdinaryGame extends Game{
counter++; counter++;
} }
public ArrayList<String> getPlayer1(){ public String getPlayer1(){
return player1.getAllPlayers(); return null;
} }
public ArrayList<String> getPlayer2(){ public String getPlayer2(){
return player2.getAllPlayers(); return null;
} }
public ArrayList<String> getAllPlayers(){ public ArrayList<String> getAllPlayers(){
ArrayList<String> rtn = player1.getAllPlayers(); return null;
rtn.addAll(player2.getAllPlayers());
return rtn;
} }
} }

View File

@ -1,10 +1,10 @@
package logistics; package uebung05.logistics;
import logistics.material.BulletBelts; import uebung05.logistics.material.BulletBelts;
import logistics.material.LiterDiesel; import uebung05.logistics.material.LiterDiesel;
import logistics.material.RocketPods; import uebung05.logistics.material.RocketPods;
class demo { class Demo {
public static void main(String[] args) { public static void main(String[] args) {
Manager ceo = new Manager(); Manager ceo = new Manager();

View File

@ -1,13 +1,13 @@
package logistics; package uebung05.logistics;
import logistics.material.BulletBelts; import uebung05.logistics.material.BulletBelts;
import logistics.material.MetGallonsKerosene; import uebung05.logistics.material.MetGallonsKerosene;
import logistics.material.RocketPods; import uebung05.logistics.material.RocketPods;
import logistics.quantities.FloatUnit; import uebung05.logistics.quantities.FloatUnit;
import logistics.quantities.IntUnit; import uebung05.logistics.quantities.IntUnit;
import logistics.quantities.NeedCollector; import uebung05.logistics.quantities.NeedCollector;
import logistics.storage.FloatStorage; import uebung05.logistics.storage.FloatStorage;
import logistics.storage.IntStorage; import uebung05.logistics.storage.IntStorage;
/** /**
* The Helicopter class represents a helicopter in the logistics system. * The Helicopter class represents a helicopter in the logistics system.

View File

@ -1,9 +1,9 @@
package logistics; package uebung05.logistics;
import logistics.quantities.FloatUnit; import uebung05.logistics.quantities.FloatUnit;
import logistics.quantities.IntUnit; import uebung05.logistics.quantities.IntUnit;
import logistics.quantities.NeedCollector; import uebung05.logistics.quantities.NeedCollector;
import logistics.quantities.Unit; import uebung05.logistics.quantities.Unit;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -63,7 +63,7 @@ public class Manager {
* *
* @return The NeedCollector object containing the needs of all the vehicles * @return The NeedCollector object containing the needs of all the vehicles
*/ */
NeedCollector collectNeeds() { public NeedCollector collectNeeds() {
NeedCollector collector = new NeedCollector(); NeedCollector collector = new NeedCollector();
for (Vehicle vehicle : vehicles) { for (Vehicle vehicle : vehicles) {
vehicle.reportNeeds(collector); vehicle.reportNeeds(collector);

View File

@ -1,7 +1,7 @@
package logistics; package uebung05.logistics;
import logistics.quantities.FloatUnit; import uebung05.logistics.quantities.FloatUnit;
import logistics.quantities.IntUnit; import uebung05.logistics.quantities.IntUnit;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;

View File

@ -1,13 +1,13 @@
package logistics; package uebung05.logistics;
import logistics.material.BulletBelts; import uebung05.logistics.material.BulletBelts;
import logistics.material.LiterDiesel; import uebung05.logistics.material.LiterDiesel;
import logistics.material.ShellBatches; import uebung05.logistics.material.ShellBatches;
import logistics.quantities.FloatUnit; import uebung05.logistics.quantities.FloatUnit;
import logistics.quantities.IntUnit; import uebung05.logistics.quantities.IntUnit;
import logistics.quantities.NeedCollector; import uebung05.logistics.quantities.NeedCollector;
import logistics.storage.FloatStorage; import uebung05.logistics.storage.FloatStorage;
import logistics.storage.IntStorage; import uebung05.logistics.storage.IntStorage;
/** /**
* The Tank class represents a tank in the logistics system. * The Tank class represents a tank in the logistics system.

View File

@ -1,12 +1,12 @@
package logistics; package uebung05.logistics;
import logistics.material.BulletBelts; import uebung05.logistics.material.BulletBelts;
import logistics.material.LiterDiesel; import uebung05.logistics.material.LiterDiesel;
import logistics.quantities.FloatUnit; import uebung05.logistics.quantities.FloatUnit;
import logistics.quantities.IntUnit; import uebung05.logistics.quantities.IntUnit;
import logistics.quantities.NeedCollector; import uebung05.logistics.quantities.NeedCollector;
import logistics.storage.FloatStorage; import uebung05.logistics.storage.FloatStorage;
import logistics.storage.IntStorage; import uebung05.logistics.storage.IntStorage;
/** /**
* The Truck class represents a truck in the logistics system. * The Truck class represents a truck in the logistics system.

View File

@ -1,11 +1,11 @@
package logistics; package uebung05.logistics;
import logistics.material.Grease; import uebung05.logistics.material.Grease;
import logistics.material.Oil; import uebung05.logistics.material.Oil;
import logistics.quantities.FloatUnit; import uebung05.logistics.quantities.FloatUnit;
import logistics.quantities.IntUnit; import uebung05.logistics.quantities.IntUnit;
import logistics.quantities.NeedCollector; import uebung05.logistics.quantities.NeedCollector;
import logistics.storage.IntStorage; import uebung05.logistics.storage.IntStorage;
/** /**
* The Vehicle abstract class represents a vehicle in the logistics system. * The Vehicle abstract class represents a vehicle in the logistics system.

View File

@ -1,6 +1,6 @@
package logistics.material; package uebung05.logistics.material;
import logistics.quantities.IntUnit; import uebung05.logistics.quantities.IntUnit;
/** /**
* The BulletBelts class represents a unit of measurement for 7.62 bullets. * The BulletBelts class represents a unit of measurement for 7.62 bullets.
@ -11,7 +11,7 @@ import logistics.quantities.IntUnit;
*/ */
public class BulletBelts implements IntUnit { public class BulletBelts implements IntUnit {
private static BulletBelts INSTANCE; public static BulletBelts INSTANCE;
private BulletBelts() {} private BulletBelts() {}

View File

@ -1,6 +1,6 @@
package logistics.material; package uebung05.logistics.material;
import logistics.quantities.IntUnit; import uebung05.logistics.quantities.IntUnit;
/** /**
* The Grease class represents a unit of measurement for grease. * The Grease class represents a unit of measurement for grease.
@ -11,7 +11,7 @@ import logistics.quantities.IntUnit;
*/ */
public class Grease implements IntUnit { public class Grease implements IntUnit {
private static Grease INSTANCE; public static Grease INSTANCE;
private Grease() {} private Grease() {}

View File

@ -1,6 +1,6 @@
package logistics.material; package uebung05.logistics.material;
import logistics.quantities.FloatUnit; import uebung05.logistics.quantities.FloatUnit;
/** /**
* The LiterDiesel class represents a unit of measurement for diesel fuel. * The LiterDiesel class represents a unit of measurement for diesel fuel.
@ -11,7 +11,7 @@ import logistics.quantities.FloatUnit;
*/ */
public class LiterDiesel implements FloatUnit { public class LiterDiesel implements FloatUnit {
private static LiterDiesel INSTANCE; public static LiterDiesel INSTANCE;
private LiterDiesel() {} private LiterDiesel() {}

View File

@ -1,6 +1,6 @@
package logistics.material; package uebung05.logistics.material;
import logistics.quantities.FloatUnit; import uebung05.logistics.quantities.FloatUnit;
/** /**
* The MetGallonsKerosene class represents a unit of measurement for kerosene. * The MetGallonsKerosene class represents a unit of measurement for kerosene.
@ -11,7 +11,7 @@ import logistics.quantities.FloatUnit;
*/ */
public class MetGallonsKerosene implements FloatUnit { public class MetGallonsKerosene implements FloatUnit {
private static MetGallonsKerosene INSTANCE; public static MetGallonsKerosene INSTANCE;
private MetGallonsKerosene() {} private MetGallonsKerosene() {}

View File

@ -1,6 +1,6 @@
package logistics.material; package uebung05.logistics.material;
import logistics.quantities.IntUnit; import uebung05.logistics.quantities.IntUnit;
/** /**
* The Oil class represents a unit of measurement for oil. * The Oil class represents a unit of measurement for oil.
@ -11,7 +11,7 @@ import logistics.quantities.IntUnit;
*/ */
public class Oil implements IntUnit { public class Oil implements IntUnit {
private static Oil INSTANCE; public static Oil INSTANCE;
private Oil() {} private Oil() {}

View File

@ -1,6 +1,6 @@
package logistics.material; package uebung05.logistics.material;
import logistics.quantities.IntUnit; import uebung05.logistics.quantities.IntUnit;
/** /**
* The RocketPods class represents a unit of measurement for 70mm rocket pods. * The RocketPods class represents a unit of measurement for 70mm rocket pods.
@ -11,7 +11,7 @@ import logistics.quantities.IntUnit;
*/ */
public class RocketPods implements IntUnit { public class RocketPods implements IntUnit {
private static RocketPods INSTANCE; public static RocketPods INSTANCE;
private RocketPods() {} private RocketPods() {}

View File

@ -1,6 +1,6 @@
package logistics.material; package uebung05.logistics.material;
import logistics.quantities.IntUnit; import uebung05.logistics.quantities.IntUnit;
/** /**
* The ShellBatches class represents a unit of measurement for 120mm shell batches. * The ShellBatches class represents a unit of measurement for 120mm shell batches.
@ -11,7 +11,7 @@ import logistics.quantities.IntUnit;
*/ */
public class ShellBatches implements IntUnit { public class ShellBatches implements IntUnit {
private static ShellBatches INSTANCE; public static ShellBatches INSTANCE;
private ShellBatches() {} private ShellBatches() {}

View File

@ -1,4 +1,4 @@
package logistics.quantities; package uebung05.logistics.quantities;
/** /**
* @author Nikolaus Köberlein * @author Nikolaus Köberlein

View File

@ -1,4 +1,4 @@
package logistics.quantities; package uebung05.logistics.quantities;
/** /**
* @author Nikolaus Köberlein * @author Nikolaus Köberlein

View File

@ -1,12 +1,12 @@
package logistics.quantities; package uebung05.logistics.quantities;
import logistics.material.BulletBelts; import uebung05.logistics.material.BulletBelts;
import logistics.material.Grease; import uebung05.logistics.material.Grease;
import logistics.material.LiterDiesel; import uebung05.logistics.material.LiterDiesel;
import logistics.material.MetGallonsKerosene; import uebung05.logistics.material.MetGallonsKerosene;
import logistics.material.Oil; import uebung05.logistics.material.Oil;
import logistics.material.RocketPods; import uebung05.logistics.material.RocketPods;
import logistics.material.ShellBatches; import uebung05.logistics.material.ShellBatches;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;

View File

@ -1,4 +1,4 @@
package logistics.quantities; package uebung05.logistics.quantities;
/** /**
* @author Nikolaus Köberlein * @author Nikolaus Köberlein

View File

@ -1,7 +1,7 @@
package logistics.storage; package uebung05.logistics.storage;
import logistics.quantities.FloatUnit; import uebung05.logistics.quantities.FloatUnit;
import logistics.quantities.NeedCollector; import uebung05.logistics.quantities.NeedCollector;
/** /**
* The FloatStorage class represents a floating-point storage for a specific FloatUnit object. * The FloatStorage class represents a floating-point storage for a specific FloatUnit object.

View File

@ -1,7 +1,7 @@
package logistics.storage; package uebung05.logistics.storage;
import logistics.quantities.IntUnit; import uebung05.logistics.quantities.IntUnit;
import logistics.quantities.NeedCollector; import uebung05.logistics.quantities.NeedCollector;
/** /**
* The IntStorage class represents an integer storage for a specific IntUnit object. * The IntStorage class represents an integer storage for a specific IntUnit object.

View File

@ -1,5 +0,0 @@
package uebung07.quantities.plain;
public class TimeUnit extends Unit{
}

View File

@ -9,7 +9,7 @@ import uebung09.iterator.Array2dIterator;
public class Board implements Iterable<Piece>{ public class Board implements Iterable<Piece>{
private final Piece[][] field = new Piece[8][8]; private final Piece[][] field = new Piece[8][8];
//private final List<Piece> pieces = new ArrayList<>(); private final List<Piece> pieces = new ArrayList<>();
void add(Piece piece) { void add(Piece piece) {
@ -42,7 +42,7 @@ public class Board implements Iterable<Piece>{
} }
public void check() { public void check() {
for (Piece p1 : iterator()) { for (Piece p1 : pieces) {
System.out.println(p1.toString()); System.out.println(p1.toString());
for (Piece p2 : pieces) for (Piece p2 : pieces)
if (p1 != p2) if (p1 != p2)

View File

@ -1,39 +1,73 @@
package uebung09.iterator; package uebung09.iterator;
import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
public class Array2dIterator<T> implements Iterator<T>{ public class Array2dIterator<T> implements Iterator<T>{
private T[][] array; private T[][] array;
private ArrayList<T> list;
private int index = 0; private int index = 0;
public Array2dIterator(T[][] array) { public Array2dIterator(T[][] array) {
this.array = array; this.array = array;
list = flatten();
} }
@Override @Override
public boolean hasNext() { public boolean hasNext() {
for (int i = 0; i < array.length; i++) { // for (int i = 0; i < array.length; i++) {
for (int j = 0; j < array[i].length; j++) { // for (int j = 0; j < array[i].length; j++) {
if (array[i][j+1] != null) { // if (array[i][j+1] != null) {
return true; // return true;
} // }
if (array[i+1][j] != null) { // if (array[i+1][j] != null) {
return true; // return true;
} // }
} // }
// }
// return false;
if (list.get(index)) {
return true;
} else {
return false;
} }
return false;
// return true;
} }
@Override @Override
public T next() { public T next() {
for (int i = 0; i < array.length; i++) { // for (int i = 0; i < array.length; i++) {
for (int j = 0; j < array[i].length; j++) { // for (int j = 0; j < array[i].length; j++) {
// if (array[i][j+1] != null) {
} // return array[i][j+1];
} // }
return null;
// }
// if (array[i+1][0] != null) {
// return array[i+1][0];
// }
// }
// return null;
return list.get(index++);
} }
private ArrayList<T> flatten(){
ArrayList<T> list = new ArrayList<>();
for (int i = 0; i < array.length; i++) {
for (int j = 0; j < array[i].length; j++) {
list.add(array[i][j]);
}
}
return list;
}
} }

View File

@ -0,0 +1,26 @@
package uebung09.iterator;
import java.util.Iterator;
import java.util.List;
public class SkipNullIterator<T> implements Iterator<T>{
public SkipNullIterator(Iterator i){
}
@Override
public boolean hasNext() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'hasNext'");
}
@Override
public T next() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'next'");
}
}