File tree Expand file tree Collapse file tree 2 files changed +8
-3
lines changed
Expand file tree Collapse file tree 2 files changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -8,9 +8,9 @@ static String[] directions(String[] goal) {
88 var stats = of (goal ).collect (groupingBy (identity (), counting ()));
99 int y = (int ) (stats .getOrDefault ("N" , 0L ) - stats .getOrDefault ("S" , 0L ));
1010 int x = (int ) (stats .getOrDefault ("E" , 0L ) - stats .getOrDefault ("W" , 0L ));
11- return (
11+ return x != 0 || y != 0 ? (
1212 "N" .repeat (Math .max (0 , y )) + "S" .repeat (Math .max (0 , -y )) +
1313 "E" .repeat (Math .max (0 , x )) + "W" .repeat (Math .max (0 , -x ))
14- ).split ("" );
14+ ).split ("" ) : new String [ 0 ] ;
1515 }
1616}
Original file line number Diff line number Diff line change @@ -7,10 +7,15 @@ class DirectionsTest {
77 @ ParameterizedTest
88 @ CsvSource (textBlock = """
99 NNNNNENN, NNNNNNNE
10+ SSNEWNWSE, S
1011 SSNEWSN, S
1112 NWSE,''
13+ N, N
14+ '', ''
1215 """ )
1316 void sample (String path , String shortest ) {
14- assertArrayEquals (shortest .split ("" ), ShortestPath .directions (path .split ("" )));
17+ String [] goal = path .isEmpty () ? new String [0 ] : path .split ("" );
18+ String [] expected = shortest .isEmpty () ? new String [0 ] : shortest .split ("" );
19+ assertArrayEquals (expected , ShortestPath .directions (goal ));
1520 }
1621}
You can’t perform that action at this time.
0 commit comments