Skip to content
Snippets Groups Projects
Commit 778d33cc authored by l13f04751's avatar l13f04751
Browse files

Final v0.1

parent 0a608262
No related branches found
No related tags found
No related merge requests found
......@@ -19,6 +19,8 @@ public class TicTacToe {
private char[] spielerZeichen = new char[2];
private char[][] spielbrett = new char [3][3];
private int anzahlZuege = 0;
public TicTacToe(TicTacToeUI ui){
......@@ -35,6 +37,8 @@ public class TicTacToe {
*/
void resetSpiel(){
anzahlZuege = 0;
for(char zeile[]: spielbrett )
{
for (int i = 0; i < zeile.length; i++) {
......@@ -171,6 +175,8 @@ public class TicTacToe {
do {
anzahlZuege++;
spielzustand = spielzug(aktuellerSpieler);
aktuellerSpieler = getNaechstenSpieler(aktuellerSpieler);
......@@ -194,9 +200,9 @@ public class TicTacToe {
for(int i=0; i<3; i++){
if ((spielbrett[i][0] + spielbrett[i][1] +
spielbrett[i][0] == 3*spieler) ||
(spielbrett[0][i] + spielbrett[1] [i] +
spielbrett[i][2] == 3*spieler) ||
(spielbrett[0][i] + spielbrett[1] [i] +
spielbrett[2][i] == 3*spieler)||
(spielbrett[0][0] + spielbrett[1][1] + spielbrett[2][2] ==
3*spieler)
||(spielbrett[2][0] + spielbrett[1][1] + spielbrett[0][2] ==
......@@ -228,6 +234,10 @@ public class TicTacToe {
public void setSpielbrett(char[][] spielbrett) {
this.spielbrett = spielbrett;
}
public int getAnzahlZuege(){
return anzahlZuege;
}
}
......
......@@ -2,8 +2,21 @@ package tictactoePraktikum;
public class MockUpClass implements TicTacToeUI{
int testcase;
int index;
String[] testcase1 = {"a", "00", "%%", "22"};
String[] testcase2 = {"11", "01", "00", "22", "10", "20", "14", "12"};
@Override
public String getZugeingabe(char[][] spielbrett, char aktuellerSpieler) {
index++;
if (testcase == 1 && index<testcase1.length){
return testcase1[index];
}
if (testcase == 2 && index<testcase2.length){
return testcase2[index];
}
return null;
}
}
......@@ -10,13 +10,15 @@ import static org.junit.Assert.*;
public class TicTacToeTest {
private static TicTacToe ttt;
private static MockUpClass mockUp;
/**
* @throws java.lang.Exception
*/
@BeforeClass
public static void SetUpBeforeClass() throws Exception {
ttt = new TicTacToe(new MockUpClass());
mockUp = new MockUpClass();
ttt = new TicTacToe(mockUp);
}
/**
......@@ -41,7 +43,7 @@ public class TicTacToeTest {
@Test
public void testGetNaechstenSpieler() {
assertEquals(1, ttt.getNaechstenSpieler(0));
assertEquals(2, ttt.getNaechstenSpieler(1));
assertEquals(0, ttt.getNaechstenSpieler(1));
assertEquals(1, ttt.getNaechstenSpieler(42));
}
......@@ -61,36 +63,69 @@ public class TicTacToeTest {
assertFalse(ttt.isGueltig(3, 0));
}
/**
* Test method for {@link tictactoePraktikum.TicTacToe#isUnentschieden()}.
*/
@Test
public void testIsUnentschieden() {
fail("Not yet implemented");
}
/**
* Test method for {@link tictactoePraktikum.TicTacToe#getSpielzustand()}.
*/
@Test
public void testGetSpielzustand() {
fail("Not yet implemented");
char[][] spielbrett0 = {{'X','X','X'},{' ',' ',' '},{' ',' ',' '}};
ttt.setSpielbrett(spielbrett0);
assertEquals(1, ttt.getSpielzustand());
char[][] spielbrett1 = {{'X',' ',' '},{'X',' ',' '},{'X',' ',' '}};
ttt.setSpielbrett(spielbrett1);
assertEquals(1, ttt.getSpielzustand());
char[][] spielbrett2 = {{'X',' ',' '},{' ','X',' '},{' ',' ','X'}};
ttt.setSpielbrett(spielbrett2);
assertEquals(1, ttt.getSpielzustand());
char[][] spielbrett3 = {{' ',' ','X'},{' ','X',' '},{'X',' ',' '}};
ttt.setSpielbrett(spielbrett3);
assertEquals(1, ttt.getSpielzustand());
char[][] spielbrett4 = {{'O','O','O'},{' ',' ',' '},{' ',' ',' '}};
ttt.setSpielbrett(spielbrett4);
assertEquals(1, ttt.getSpielzustand());
char[][] spielbrett5 = {{'O',' ',' '},{'O',' ',' '},{'O',' ',' '}};
ttt.setSpielbrett(spielbrett5);
assertEquals(1, ttt.getSpielzustand());
char[][] spielbrett6 = {{'O',' ',' '},{' ','O',' '},{' ',' ','O'}};
ttt.setSpielbrett(spielbrett6);
assertEquals(1, ttt.getSpielzustand());
char[][] spielbrett7 = {{' ',' ','O'},{' ','O',' '},{'O',' ',' '}};
ttt.setSpielbrett(spielbrett7);
assertEquals(1, ttt.getSpielzustand());
char[][] spielbrett8 = {{'X','X','O'},{'O','O','X'},{'X','X','O'}};
ttt.setSpielbrett(spielbrett8);
assertEquals(2, ttt.getSpielzustand());
char[][] spielbrett9 = {{' ',' ',' '},{' ',' ',' '},{' ',' ',' '}};
ttt.setSpielbrett(spielbrett9);
assertEquals(3, ttt.getSpielzustand());
}
/**
* Test method for {@link tictactoePraktikum.TicTacToe#spielzug(int)}.
*/
@Test (expected=IndexOutOfBoundsException.class)
@Test
public void testSpielzug() {
ttt.spielzug(3);
char[][] spielbrett1 = {{' ',' ',' '},{' ','X',' '},{' ',' ',' '}};
char[][] spielbrett2 = {{'O',' ',' '},{' ','X',' '},{' ',' ',' '}};
char[][] spielbrett3 = {{'O',' ',' '},{' ','X',' '},{' ',' ','O'}};
mockUp.testcase = 1;
mockUp.index = -1;
ttt.setSpielbrett(spielbrett1);
assertEquals(4, ttt.spielzug(1));
assertArrayEquals(spielbrett1, ttt.getSpielbrett());
assertEquals(3, ttt.spielzug(1));
assertArrayEquals(spielbrett2, ttt.getSpielbrett());
assertEquals(3, ttt.spielzug(1));
assertEquals(3, mockUp.index);
assertArrayEquals(spielbrett3, ttt.getSpielbrett());
}
/**
* Test method for {@link tictactoePraktikum.TicTacToe#spiel(int)}.
* Test method for {@link tictactoePraktikum.TicTacToe#spielzug(int)} for an IndexOutOfBoundsException.
*/
@Test
public void testSpiel() {
fail("Not yet implemented");
@Test (expected=IndexOutOfBoundsException.class)
public void testSpielzugForIndexOutOFBoundsException() {
ttt.spielzug(3);
}
/**
......@@ -108,19 +143,16 @@ public class TicTacToeTest {
}
/**
* Test method for {@link tictactoePraktikum.TicTacToe#getSpielbrett()}.
*/
@Test
public void testGetSpielbrett() {
fail("Not yet implemented");
}
/**
* Test method for {@link tictactoePraktikum.TicTacToe#setSpielbrett(char[][])}.
* Test method for {@link tictactoePraktikum.TicTacToe#spiel()}.
*/
@Test
public void testSetSpielbrett() {
fail("Not yet implemented");
public void testSpiel() {
char[][] spielbrett = {{' ',' ',' '},{' ',' ',' '},{' ',' ',' '}};
ttt.setSpielbrett(spielbrett);
mockUp.testcase = 2;
mockUp.index = -1;
ttt.spiel(0);
assertEquals('X', ttt.getGewinner());
assertEquals(7, ttt.getAnzahlZuege());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment