Commit 2a341b7f by Paktalin

Lesson 2 is done

parent a46fdc5e
package com.example.paktalin.agilejava_exercises;
import com.example.paktalin.agilejava_exercises.pieces.Pawn;
import java.util.ArrayList;
import java.util.List;
/**
* Created by Paktalin on 23/05/2018.
*/
class Board {
private List<Pawn> pawns = new ArrayList<>();
int getNumberOfPieces() {
return pawns.size();
}
void addPawn(Pawn pawn) {
pawns.add(pawn);
}
Pawn getPawn(int index) {
return pawns.get(index);
}
}
package com.example.paktalin.agilejava_exercises;
package com.example.paktalin.agilejava_exercises.pieces;
/**
* Created by Paktalin on 23/05/2018.
*/
class Pawn {
private String color = "white";
public class Pawn {
public static String COLOR_WHITE = "white";
public static String COLOR_BLACK = "black";
Pawn(final String color) {
private String color;
public Pawn() {
color = "white";
}
public Pawn(final String color) {
this.color = color;
}
String getColor() {
public String getColor() {
return color;
}
}
package com.example.paktalin.agilejava_exercises;
import com.example.paktalin.agilejava_exercises.pieces.PawnTest;
import junit.framework.TestSuite;
/**
* Created by Paktalin on 23/05/2018.
*/
public class AllTests extends TestSuite {
public static TestSuite suite() {
TestSuite suite = new TestSuite();
suite.addTestSuite(PawnTest.class);
suite.addTestSuite(BoardTest.class);
return suite;
}
}
package com.example.paktalin.agilejava_exercises;
import com.example.paktalin.agilejava_exercises.pieces.Pawn;
import junit.framework.TestCase;
/**
* Created by Paktalin on 23/05/2018.
*/
public class BoardTest extends TestCase {
private Board board;
public void setUp() {
board = new Board();
}
public void testBoard() {
assertEquals(0, board.getNumberOfPieces());
}
public void testNumberOfPieces() {
Pawn pawn = new Pawn(Pawn.COLOR_BLACK);
board.addPawn(pawn);
assertEquals(1, board.getNumberOfPieces());
assertEquals("black", board.getPawn(0).getColor());
}
}
package com.example.paktalin.agilejava_exercises;
package com.example.paktalin.agilejava_exercises.pieces;
import junit.framework.TestCase;
import static com.example.paktalin.agilejava_exercises.pieces.Pawn.COLOR_BLACK;
import static com.example.paktalin.agilejava_exercises.pieces.Pawn.COLOR_WHITE;
/**
* Created by Paktalin on 23/05/2018.
*/
......@@ -9,13 +12,15 @@ import junit.framework.TestCase;
public class PawnTest extends TestCase {
public void testCreate() {
String COLOR_WHITE = "white";
String COLOR_BLACK = "black";
Pawn pawn = new Pawn(COLOR_WHITE);
assertEquals("white", pawn.getColor());
Pawn pawn2 = new Pawn(COLOR_BLACK);
assertEquals("black", pawn2.getColor());
}
public void testConstructor() {
Pawn pawn = new Pawn();
assertEquals("white", pawn.getColor());
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment