Repository navigation
Expand file tree
/
Copy pathRottingOrangesTest.java
More file actions
95 lines (77 loc) Β· 2.38 KB
/
Copy pathRottingOrangesTest.java
File metadata and controls
95 lines (77 loc) Β· 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package bfs.oranges;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
class RottingOrangesTest {
@Test
void orangesRotting_LeetCodeExample1_ExpectedOutput4() {
// Given
int[][] grid = {
{2, 1, 1},
{1, 1, 0},
{0, 1, 1}
};
// When
int actualMinutes = new RottingOranges().orangesRotting(grid);
// Then
assertThat(actualMinutes).isEqualTo(4);
}
@Test
void orangesRotting_LeetCodeExample2_ImpossibleFreshFruitRemains() {
// Given
int[][] grid = {
{2, 1, 1},
{0, 1, 1},
{1, 0, 1}
};
// When
int actualMinutes = new RottingOranges().orangesRotting(grid);
// Then
assertThat(actualMinutes).isEqualTo(-1);
}
@Test
void orangesRotting_LeetCodeExample3_OutputAlreadyAllRotten() {
// Given
int[][] grid = { {0, 2} };
// When
int actualMinutes = new RottingOranges().orangesRotting(grid);
// Then
assertThat(actualMinutes).isEqualTo(0);
}
/**
* Make sure to mark fresh fruit as rotten in a single pass before finding adjacent fresh fruit from recently rotten.
*/
@Test
void orangesRotting_HandleAdjacentFresh_ExpectedOutput() {
// Given
int[][] grid = {
{2,2},
{1,1},
{0,0},
{2,0}
};
// When
int actualMinutes = new RottingOranges().orangesRotting(grid);
// Then
assertThat(actualMinutes).isEqualTo(1);
}
@Test
void orangesRotting_MaxGridCornerSource_Output18() {
// Given
int[][] grid = new int[][] {
{ 2, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
};
// When
int actualMinutes = new RottingOranges().orangesRotting(grid);
// Then
assertThat(actualMinutes).isEqualTo(18);
}
}