refactored testing

This commit is contained in:
Johannes Schmelz 2024-06-14 00:33:41 +02:00
parent 440eed0e9d
commit e59cbb88f1
31 changed files with 41 additions and 16 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.

View File

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

View File

@ -1,9 +1,10 @@
package iterator; package test.uebung.uebung09.iterator;
import org.junit.Test; import org.junit.Test;
import java.util.Iterator; import java.util.Iterator;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import uebung09.iterator.Array2dIterator;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;

View File

@ -1,10 +1,12 @@
package iterator; package test.uebung.uebung09.iterator;
import org.junit.Test; import org.junit.Test;
import java.util.Iterator; import java.util.Iterator;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import uebung09.iterator.*;
import static java.util.Arrays.asList; import static java.util.Arrays.asList;
import static java.util.Collections.emptyList; import static java.util.Collections.emptyList;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;

View File

@ -1,16 +1,16 @@
package uebung09.chess; package uebung09.chess;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import java.util.List; import java.util.List;
import uebung09.iterator.Array2dIterator; import uebung09.iterator.Array2dIterator;
public class Board extends Array2dIterator<Piece>{
private final Piece[][] field = new Piece[8][8];
private final List<Piece> pieces = new ArrayList<>();
Board(){ public class Board implements Iterable<Piece>{
private final Piece[][] field = new Piece[8][8];
} //private final List<Piece> pieces = new ArrayList<>();
void add(Piece piece) { void add(Piece piece) {
if (piece.getBoard() != this) if (piece.getBoard() != this)
@ -42,7 +42,7 @@ public class Board extends Array2dIterator<Piece>{
} }
public void check() { public void check() {
for (Piece p1 : pieces) { for (Piece p1 : iterator()) {
System.out.println(p1.toString()); System.out.println(p1.toString());
for (Piece p2 : pieces) for (Piece p2 : pieces)
if (p1 != p2) if (p1 != p2)
@ -56,4 +56,11 @@ public class Board extends Array2dIterator<Piece>{
public String toString() { public String toString() {
return pieces.toString(); return pieces.toString();
} }
@Override
public Iterator<Piece> iterator() {
// TODO Auto-generated method stub
return new Array2dIterator<>(null);
//throw new UnsupportedOperationException("Unimplemented method 'iterator'");
}
} }

View File

@ -45,6 +45,7 @@ public class ChessApp {
case WHITE_QUEEN -> addQueen(Color.white); case WHITE_QUEEN -> addQueen(Color.white);
case BLACK_KNIGHT -> addKnight(Color.black); case BLACK_KNIGHT -> addKnight(Color.black);
case WHITE_KNIGHT -> addKnight(Color.white); case WHITE_KNIGHT -> addKnight(Color.white);
case ITERATOR -> board.iterator();
default -> System.out.println("Invalid command " + command); default -> System.out.println("Invalid command " + command);
} }
} }

View File

@ -4,22 +4,36 @@ import java.util.Iterator;
public class Array2dIterator<T> implements Iterator<T>{ public class Array2dIterator<T> implements Iterator<T>{
private T[][] array;
private int index = 0;
public <T> Array2dIterator(T[][] aaray) { public Array2dIterator(T[][] array) {
this.array = array;
} }
@Override @Override
public boolean hasNext() { public boolean hasNext() {
// TODO Auto-generated method stub for (int i = 0; i < array.length; i++) {
for (int j = 0; j < array[i].length; j++) {
if (array[i][j+1] != null) {
return true;
}
if (array[i+1][j] != null) {
return true;
}
}
}
return false; return false;
} }
@Override @Override
public T next() { public T next() {
// TODO Auto-generated method stub for (int i = 0; i < array.length; i++) {
for (int j = 0; j < array[i].length; j++) {
}
}
return null; return null;
} }
} }