55import org .junit .Test ;
66
77import java .io .IOException ;
8+ import java .net .URISyntaxException ;
9+ import java .nio .file .Files ;
10+ import java .nio .file .Paths ;
11+ import java .util .ArrayList ;
12+ import java .util .List ;
813
914import static org .junit .Assert .assertEquals ;
1015import static org .junit .Assert .assertFalse ;
1318 * @author Grigoriy Lyashenko (Grog).
1419 */
1520public class IoUtilsTest {
16- private final String examplePizzaFile = "inputDataSets/example.in" ;
21+ private static final String TEST_OUTPUT_FILE = "testOutput.txt" ;
22+ private static final String PARAGON_OUTPUT_EXAMPLE_FILE = "src/test/resources/paragonOutputExample.txt" ;
23+ private static final String EXAMPLE_PIZZA_FILE = "inputDataSets/example.in" ;
24+
25+ private static List <List <Cell >> createSlicesForParagonOutputExample () {
26+ List <List <Cell >> resultList = new ArrayList <>();
27+ List <Cell > slice0 = new ArrayList <>();
28+ List <Cell > slice1 = new ArrayList <>();
29+ List <Cell > slice2 = new ArrayList <>();
30+
31+ slice0 .add (new Cell (0 , 0 , Ingredient .TOMATO ));
32+ slice0 .add (new Cell (0 , 1 , Ingredient .TOMATO ));
33+ slice0 .add (new Cell (0 , 2 , Ingredient .TOMATO ));
34+ slice0 .add (new Cell (1 , 0 , Ingredient .TOMATO ));
35+ slice0 .add (new Cell (1 , 1 , Ingredient .MUSHROOM ));
36+ slice0 .add (new Cell (1 , 2 , Ingredient .TOMATO ));
37+
38+ slice1 .add (new Cell (2 , 0 , Ingredient .TOMATO ));
39+ slice1 .add (new Cell (2 , 1 , Ingredient .MUSHROOM ));
40+ slice1 .add (new Cell (2 , 2 , Ingredient .TOMATO ));
41+
42+ slice2 .add (new Cell (3 , 0 , Ingredient .TOMATO ));
43+ slice2 .add (new Cell (3 , 1 , Ingredient .MUSHROOM ));
44+ slice2 .add (new Cell (3 , 2 , Ingredient .TOMATO ));
45+ slice2 .add (new Cell (4 , 0 , Ingredient .TOMATO ));
46+ slice2 .add (new Cell (4 , 1 , Ingredient .TOMATO ));
47+ slice2 .add (new Cell (4 , 2 , Ingredient .TOMATO ));
48+
49+ resultList .add (slice0 );
50+ resultList .add (slice1 );
51+ resultList .add (slice2 );
52+
53+ return resultList ;
54+ }
1755
1856 @ Test
1957 public void parseExampleInput () throws IOException {
20- Cell [][] ingredients = IoUtils .parsePizza (examplePizzaFile );
21- assertEquals ("We expect" + examplePizzaFile + "contains 3 rows" , 3 , ingredients .length );
22- assertEquals ("We expect" + examplePizzaFile + "contains 5 columns" , 5 , ingredients [0 ].length );
58+ Cell [][] ingredients = IoUtils .parsePizza (EXAMPLE_PIZZA_FILE );
59+ assertEquals ("We expect" + EXAMPLE_PIZZA_FILE + "contains 3 rows" , 3 , ingredients .length );
60+ assertEquals ("We expect" + EXAMPLE_PIZZA_FILE + "contains 5 columns" , 5 , ingredients [0 ].length );
2361 assertFalse ("We expect no null value in ingredients" , IoUtils .convertToHumanReadableTable (ingredients ).contains ("null" ));
2462 }
2563
2664 @ Test
2765 public void parseExampleSliceInstructions () throws IOException {
2866 assertEquals ("We expect min 1 ingredient per slice" , 1 ,
29- IoUtils .parseSliceInstructions (examplePizzaFile ).getMinNumberOfIngredientPerSlice ().intValue ());
67+ IoUtils .parseSliceInstructions (EXAMPLE_PIZZA_FILE ).getMinNumberOfIngredientPerSlice ().intValue ());
3068 assertEquals ("We expect max 6 cells per slice" , 6 ,
31- IoUtils .parseSliceInstructions (examplePizzaFile ).getMaxNumberOfCellsPerSlice ().intValue ());
69+ IoUtils .parseSliceInstructions (EXAMPLE_PIZZA_FILE ).getMaxNumberOfCellsPerSlice ().intValue ());
70+ }
71+
72+ @ Test
73+ public void parseSlicesToOutputFormat () throws IOException , URISyntaxException {
74+ //Given a list of slices
75+ List <List <Cell >> slicesForParagonOutputExample = createSlicesForParagonOutputExample ();
76+ //Then parse slices according to the output format
77+ String outputDate = IoUtils .parseSlices (slicesForParagonOutputExample );
78+ IoUtils .writeToFile (TEST_OUTPUT_FILE , outputDate );
79+ assertEquals (IoUtils .readFromFile (PARAGON_OUTPUT_EXAMPLE_FILE ), IoUtils .readFromFile (TEST_OUTPUT_FILE ));
80+ //clean the file under the test
81+ Files .deleteIfExists (Paths .get (TEST_OUTPUT_FILE ));
3282 }
3383}
0 commit comments