Skip to content

Commit 8c43d97

Browse files
committed
pizzaHumanReadableOutput. Add coordinates output
1 parent 0970138 commit 8c43d97

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

src/main/java/com/google/hashcode/entity/Pizza.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,30 @@ public SliceInstruction getSliceInstruction() {
5353
@Override
5454
public String toString() {
5555
return input.toString()
56-
+ "\n" + sliceInstruction.toString()
57-
+ "\n" + outputCellsArray();
56+
+ ("\n" + sliceInstruction.toString()
57+
+ "\n" + outputCellsArray()).trim();
5858
}
5959

6060
private String outputCellsArray() {
6161
StringBuilder stringBuilder = new StringBuilder();
6262
int columnsCount = cells.stream().max(Comparator.comparingInt(Cell::getX)).get().getX();
6363
int rowsCount = cells.stream().max(Comparator.comparingInt(Cell::getY)).get().getY();
64-
for (int i = 0; i < rowsCount + 1; i++) {
65-
for (int j = 0; j < columnsCount + 1; j++) {
66-
stringBuilder.append(this.getCell(i, j).toString()).append(" ");
64+
//output columns coordinates
65+
stringBuilder.append(" ");
66+
for (int column = 0; column < columnsCount + 1; column++) {
67+
stringBuilder.append(" ").append(column);
68+
}
69+
stringBuilder.append("\n");
70+
for (int row = 0; row < rowsCount + 1; row++) {
71+
//output rows coordinates
72+
stringBuilder.append(row).append(" ");
73+
for (int column = 0; column < columnsCount + 1; column++) {
74+
stringBuilder.append(this.getCell(row, column).toString()).append(" ");
6775
}
6876
stringBuilder.append("\n");
6977
}
7078
return stringBuilder.toString();
7179
}
7280

81+
7382
}

src/test/java/com/google/hashcode/entity/PizzaTest.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
package com.google.hashcode.entity;
22

3-
import com.google.hashcode.utils.InputFiles;
43
import com.google.hashcode.utils.IoUtils;
54
import org.junit.Test;
65

76
import java.io.File;
87
import java.io.IOException;
98

10-
import static com.google.hashcode.utils.InputFiles.*;
9+
import static com.google.hashcode.utils.InputFiles.EXAMPLE_INPUT_FILE_PATH;
1110
import static org.junit.Assert.assertEquals;
1211

1312
/**
@@ -31,6 +30,12 @@ public void getCellException() throws Exception {
3130
public void testToString() throws IOException {
3231
Pizza pizza = new Pizza(new File(EXAMPLE_INPUT_FILE_PATH), IoUtils.parsePizza(EXAMPLE_INPUT_FILE_PATH), IoUtils.parseSliceInstructions(EXAMPLE_INPUT_FILE_PATH));
3332
System.out.println(pizza);
33+
assertEquals("inputDataSets/example.inSliceInstructions: \n" +
34+
"min 1 ingredient per slice, max 6 cells per slice \n" +
35+
" 0 1 2 3 4\n" +
36+
"0 T T T T T \n" +
37+
"1 T M M M T \n" +
38+
"2 T T T T T", pizza.toString());
3439
}
3540

3641
}

src/test/java/com/google/hashcode/utils/IoUtilsTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import java.util.Arrays;
1313
import java.util.List;
1414

15-
import static junit.framework.TestCase.assertFalse;
1615
import static org.junit.Assert.assertEquals;
1716

1817
/**
@@ -51,8 +50,7 @@ private static List<Slice> createSlicesForParagonOutputExample() {
5150

5251
@Test
5352
public void parseExampleInput() throws IOException {
54-
List<Cell> ing = IoUtils.parsePizza(EXAMPLE_PIZZA_FILE);
55-
53+
List<Cell> input = IoUtils.parsePizza(EXAMPLE_PIZZA_FILE);
5654
}
5755

5856
@Test

0 commit comments

Comments
 (0)