Permalink
Browse files

[tdd-diamond] Calculate the collumn of left letters

  • Loading branch information...
michaelszymczak committed Apr 9, 2017
1 parent 5bb73a9 commit e65563a37f419facebebdbbbc30ff990e1a2b681
@@ -19,25 +19,25 @@ public String rendered() {
if (letter == A)
{
Layout layout = Layout.forLastLetterBeing(A);
return new Board(new PositionedLetter(ofYX(layout.yOfTop(A),0), A)).toString();
return new Board(new PositionedLetter(ofYX(layout.yOfTop(A),layout.xOfLeft(A)), A)).toString();
}
if (letter == B)
{
Layout layout = Layout.forLastLetterBeing(B);
return new Board(
new PositionedLetter(ofYX(layout.yOfTop(A),1), A),
new PositionedLetter(ofYX(layout.yOfTop(B),0), B), new PositionedLetter(ofYX(layout.yOfTop(B),2), B),
new PositionedLetter(ofYX(layout.yOfTop(A),layout.xOfLeft(A)), A),
new PositionedLetter(ofYX(layout.yOfTop(B),layout.xOfLeft(B)), B), new PositionedLetter(ofYX(layout.yOfTop(B),2), B),
new PositionedLetter(ofYX(layout.yOfBottom(A),1), A)
).toString();
}

Layout layout = Layout.forLastLetterBeing(C);
return new Board(
new PositionedLetter(ofYX(layout.yOfTop(A),2), A),
new PositionedLetter(ofYX(layout.yOfTop(B),1), B), new PositionedLetter(ofYX(layout.yOfTop(B),3), B),
new PositionedLetter(ofYX(layout.yOfTop(C),0), C), new PositionedLetter(ofYX(layout.yOfTop(C),4), C),
new PositionedLetter(ofYX(layout.yOfBottom(B),1), B), new PositionedLetter(ofYX(layout.yOfBottom(B),3), B),
new PositionedLetter(ofYX(layout.yOfBottom(A),2), A)
new PositionedLetter(ofYX(layout.yOfTop(A),layout.xOfLeft(A)), A),
new PositionedLetter(ofYX(layout.yOfTop(B),layout.xOfLeft(B)), B), new PositionedLetter(ofYX(layout.yOfTop(B),3), B),
new PositionedLetter(ofYX(layout.yOfTop(C),layout.xOfLeft(C)), C), new PositionedLetter(ofYX(layout.yOfTop(C),4), C),
new PositionedLetter(ofYX(layout.yOfBottom(B),layout.xOfLeft(B)), B), new PositionedLetter(ofYX(layout.yOfBottom(B),3), B),
new PositionedLetter(ofYX(layout.yOfBottom(A),layout.xOfLeft(A)), A)
).toString();

}
@@ -19,4 +19,9 @@ public int yOfTop(Letter letter) {
public int yOfBottom(Letter letter) {
return lastLetter.ordinal() * 2 - letter.ordinal();
}

public int xOfLeft(Letter letter) {
return lastLetter.ordinal() - letter.ordinal();
}

}
@@ -2,28 +2,46 @@ package com.michaelszymczak.diamond

import spock.lang.Specification

import static com.michaelszymczak.diamond.Layout.forLastLetterBeing
import static com.michaelszymczak.diamond.Letter.A
import static com.michaelszymczak.diamond.Letter.B
import static com.michaelszymczak.diamond.Letter.C
import static com.michaelszymczak.diamond.Letter.D

class LayoutShould extends Specification {

def "let the top letter to be in ordinal number distance from the top"() {
given:
def layout = layout()

expect:
layout.yOfTop(Letter.A) == 0
layout.yOfTop(Letter.C) == 2
layout.yOfTop(A) == 0
layout.yOfTop(C) == 2
}

def "let the bottom letter to be in ordinal number distance from the bottom which is twice the ordinal number of the max letter"() {
given:
def layout = Layout.forLastLetterBeing(Letter.D)
def layout = forLastLetterBeing(D)

expect:
layout.yOfBottom(D) == 3
layout.yOfBottom(C) == 4
layout.yOfBottom(B) == 5
layout.yOfBottom(A) == 6
}

def "let the left letter to be in reverse ordinal number distance from the left"() {
given:
def layout = forLastLetterBeing(D)

expect:
layout.yOfBottom(Letter.D) == 3
layout.yOfBottom(Letter.C) == 4
layout.yOfBottom(Letter.B) == 5
layout.yOfBottom(Letter.A) == 6
layout.xOfLeft(D) == 0
layout.xOfLeft(C) == 1
layout.xOfLeft(B) == 2
layout.xOfLeft(A) == 3
}

private static Layout layout() {
Layout.forLastLetterBeing(Letter.C)
forLastLetterBeing(C)
}
}

0 comments on commit e65563a

Please sign in to comment.