Permalink
Browse files

[tdd-diamond] Diamond of C

  • Loading branch information...
michaelszymczak committed Apr 9, 2017
1 parent 0906c04 commit ab42e6db69bc18e95af132b7ccd495a335808149
@@ -1,8 +1,7 @@
package com.michaelszymczak.diamond;

import static com.michaelszymczak.diamond.Coordinates.ofYX;
import static com.michaelszymczak.diamond.Letter.A;
import static com.michaelszymczak.diamond.Letter.B;
import static com.michaelszymczak.diamond.Letter.*;

public class Diamond {

@@ -17,11 +16,26 @@ private Diamond(Letter letter) {
}

public String rendered() {
return letter == A ? new Board(new PositionedLetter(ofYX(0,0), A)).toString()
: new Board(
new PositionedLetter(ofYX(0,1), A),
new PositionedLetter(ofYX(1,0), B), new PositionedLetter(ofYX(1,2), B),
new PositionedLetter(ofYX(2,1), A)
if (letter == A)
{
return new Board(new PositionedLetter(ofYX(0,0), A)).toString();
}
if (letter == B)
{
return new Board(
new PositionedLetter(ofYX(0,1), A),
new PositionedLetter(ofYX(1,0), B), new PositionedLetter(ofYX(1,2), B),
new PositionedLetter(ofYX(2,1), A)
).toString();
}

return new Board(
new PositionedLetter(ofYX(0,2), A),
new PositionedLetter(ofYX(1,1), B), new PositionedLetter(ofYX(1,3), B),
new PositionedLetter(ofYX(2,0), C), new PositionedLetter(ofYX(2,4), C),
new PositionedLetter(ofYX(3,1), B), new PositionedLetter(ofYX(3,3), B),
new PositionedLetter(ofYX(4,2), A)
).toString();

}
}
@@ -9,11 +9,23 @@ class DiamondAcceptanceTest extends Specification {
Diamond.of(Letter.A).rendered() == "A"
}

def "creates diamond shape if more than one letter"() {
def "uses all letters up to the provided one"() {
expect:
Diamond.of(Letter.B).rendered() == "" +
" A " + "\n" +
"B B" + "\n" +
" A "
}

def "creates diamond-like shape"() {
expect:
Diamond.of(Letter.C).rendered() == "" +
" A " + "\n" +
" B B " + "\n" +
"C C" + "\n" +
" B B " + "\n" +
" A "
}


}

0 comments on commit ab42e6d

Please sign in to comment.