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) {
8
8
var stats = of (goal ).collect (groupingBy (identity (), counting ()));
9
9
int y = (int ) (stats .getOrDefault ("N" , 0L ) - stats .getOrDefault ("S" , 0L ));
10
10
int x = (int ) (stats .getOrDefault ("E" , 0L ) - stats .getOrDefault ("W" , 0L ));
11
- return (
11
+ return x != 0 || y != 0 ? (
12
12
"N" .repeat (Math .max (0 , y )) + "S" .repeat (Math .max (0 , -y )) +
13
13
"E" .repeat (Math .max (0 , x )) + "W" .repeat (Math .max (0 , -x ))
14
- ).split ("" );
14
+ ).split ("" ) : new String [ 0 ] ;
15
15
}
16
16
}
Original file line number Diff line number Diff line change @@ -7,10 +7,15 @@ class DirectionsTest {
7
7
@ ParameterizedTest
8
8
@ CsvSource (textBlock = """
9
9
NNNNNENN, NNNNNNNE
10
+ SSNEWNWSE, S
10
11
SSNEWSN, S
11
12
NWSE,''
13
+ N, N
14
+ '', ''
12
15
""" )
13
16
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 ));
15
20
}
16
21
}
You can’t perform that action at this time.
0 commit comments