Skip to content

Commit 2c3deba

Browse files
author
Jakub Lendzinski
committed
Meadow - printing empty board
1 parent 53531f6 commit 2c3deba

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

src/main/java/MeadowBoard.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,19 @@ public boolean isFieldEmpty(int x, int y){
1818
return this.meadow[x][y] == null;
1919
}
2020

21+
22+
public void printBoard(){
23+
for (int iX = 0; iX < xSize; iX++){
24+
for (int iY = 0; iY < ySize; iY++){
25+
26+
if (this.isFieldEmpty(iX, iY)){
27+
System.out.print(this.meadowEmoji);
28+
} else {
29+
// not implemented yet
30+
}
31+
32+
}
33+
System.out.println("");
34+
}
35+
}
2136
}

src/test/java/TestMeadowBord.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,29 @@
1+
import org.junit.After;
12
import org.junit.Test;
23
import org.junit.Before;
4+
5+
import java.io.ByteArrayOutputStream;
6+
import java.io.PrintStream;
7+
38
import static org.junit.Assert.*;
49

510
public class TestMeadowBord {
611

712
MeadowBoard board;
13+
ByteArrayOutputStream outContent;
14+
PrintStream originalOut;
815

916
@Before
1017
public void setup(){
1118
this.board = new MeadowBoard(10, 12);
19+
this.outContent = new ByteArrayOutputStream();
20+
this.originalOut = System.out;
21+
System.setOut(new PrintStream(this.outContent));
22+
}
23+
24+
@After
25+
public void teardown(){
26+
System.setOut(this.originalOut);
1227
}
1328

1429
@Test
@@ -23,4 +38,13 @@ public void testIsEmptyWhenEmpty(){
2338
assertTrue(this.board.isFieldEmpty(0, 0));
2439
}
2540

41+
@Test
42+
public void testPrintBoardLineEmpty(){
43+
this.board.printBoard();
44+
assertTrue(this.outContent
45+
.toString()
46+
.contains("\uD83D\uDFE9\uD83D\uDFE9\uD83D\uDFE9\uD83D\uDFE9\uD83D\uDFE9\uD83D\uDFE9\uD83D" +
47+
"\uDFE9\uD83D\uDFE9\uD83D\uDFE9\uD83D\uDFE9\uD83D\uDFE9\uD83D\uDFE9"));
48+
}
49+
2650
}

0 commit comments

Comments
 (0)