Skip to content

Commit 19370fa

Browse files
committed
F!! storyboard has better spacing
1 parent 85cf995 commit 19370fa

File tree

3 files changed

+85
-59
lines changed

3 files changed

+85
-59
lines changed
Lines changed: 56 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,56 @@
1-
Game of Life
2-
3-
Initial:
4-
. . . . .
5-
. . . . .
6-
. x x x .
7-
. . . . .
8-
. . . . .
9-
10-
11-
Start Game:
12-
. . . . .
13-
. . x . .
14-
. . x . .
15-
. . x . .
16-
. . . . .
17-
18-
19-
Frame #2:
20-
. . . . .
21-
. . . . .
22-
. x x x .
23-
. . . . .
24-
. . . . .
25-
26-
27-
setting alive: *
28-
setting dead: _
29-
30-
Frame #3:
31-
_ _ _ _ _
32-
_ _ * _ _
33-
_ _ * _ _
34-
_ _ * _ _
35-
_ _ _ _ _
36-
37-
38-
Frame #4:
39-
_ _ _ _ _
40-
_ _ _ _ _
41-
_ * * * _
42-
_ _ _ _ _
43-
_ _ _ _ _
1+
Game of Life
2+
3+
4+
Initial:
5+
. . . . .
6+
. . . . .
7+
. x x x .
8+
. . . . .
9+
. . . . .
10+
11+
12+
Start Game:
13+
. . . . .
14+
. . x . .
15+
. . x . .
16+
. . x . .
17+
. . . . .
18+
19+
20+
Frame #2:
21+
. . . . .
22+
. . . . .
23+
. x x x .
24+
. . . . .
25+
. . . . .
26+
27+
28+
setting alive: *
29+
setting dead: _
30+
31+
32+
Frame #3:
33+
_ _ _ _ _
34+
_ _ * _ _
35+
_ _ * _ _
36+
_ _ * _ _
37+
_ _ _ _ _
38+
39+
40+
Frame #4:
41+
_ _ _ _ _
42+
_ _ _ _ _
43+
_ * * * _
44+
_ _ _ _ _
45+
_ _ _ _ _
46+
47+
48+
setting dead:
49+
50+
51+
Frame #5:
52+
53+
*
54+
*
55+
*
56+

approvaltests-tests/src/test/java/org/approvaltests/StoryBoardTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ void gameOfLifeWithDescription()
3434
storyboard.addDescriptionWithData("setting alive", gameOfLife.setAliveCell("*"));
3535
storyboard.addDescriptionWithData("setting dead", gameOfLife.setDeadCell("_"));
3636
storyboard.addFrames(2, gameOfLife::advance);
37+
storyboard.addDescriptionWithData("setting dead", gameOfLife.setDeadCell(" "));
38+
storyboard.addFrames(1, gameOfLife::advance);
3739
Approvals.verify(storyboard);
3840
}
3941
private static class GameOfLife

approvaltests/src/main/java/org/approvaltests/StoryBoard.java

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44

55
public class StoryBoard
66
{
7+
enum Types {None, Description, Frame}
78
private StringBuffer stringBuffer = new StringBuffer();
89
int index = 0;
9-
private boolean newLineNeeded = false;
10+
private Types last = Types.None;
1011
public static <T> StoryBoard createSequence(T initial, int additionalFrames, Function0<T> getNextFrame)
1112
{
1213
return new StoryBoard().add(initial).addFrames(additionalFrames, getNextFrame);
@@ -18,11 +19,29 @@ public <T> StoryBoard add(T object)
1819
}
1920
public <T> StoryBoard addFrame(String title, T frame)
2021
{
21-
String frameTitle = index == 0 ? title : "\n\n" + title;
22+
addNewLines(Types.Frame);
23+
String frameTitle = title;
2224
stringBuffer.append(String.format("%s:\n%s", frameTitle, frame));
2325
index++;
2426
return this;
2527
}
28+
29+
private void addNewLines(Types type) {
30+
switch (last){
31+
case None:
32+
break;
33+
case Description:
34+
if (type == Types.Frame){
35+
stringBuffer.append("\n\n");
36+
}
37+
break;
38+
case Frame:
39+
stringBuffer.append("\n\n");
40+
break;
41+
}
42+
last = type;
43+
}
44+
2645
public <T> StoryBoard addFrames(int howMany, Function0<T> getNextFrame)
2746
{
2847
for (int i = 0; i < howMany; i++)
@@ -36,28 +55,20 @@ public String toString()
3655
{
3756
return stringBuffer.toString();
3857
}
39-
public void addDescription(String game_of_life)
58+
public StoryBoard addDescription(String game_of_life)
4059
{
41-
stringBuffer.append(game_of_life);
42-
stringBuffer.append("\n");
43-
stringBuffer.append("\n");
60+
addNewLines(Types.Description);
61+
stringBuffer.append(game_of_life+"\n");
62+
return this;
4463
}
4564
public <T> StoryBoard addFrame(T frame)
4665
{
4766
return add(frame);
4867
}
4968
public <T> StoryBoard addDescriptionWithData(String description, String data)
5069
{
51-
if (newLineNeeded)
52-
{
53-
stringBuffer.append("\n");
54-
}
55-
else
56-
{
57-
stringBuffer.append("\n\n");
58-
}
59-
newLineNeeded = true;
60-
stringBuffer.append(description + ": " + data);
70+
addNewLines(Types.Description);
71+
stringBuffer.append(description + ": " + data + "\n");
6172
return this;
6273
}
6374
}

0 commit comments

Comments
 (0)