-
Notifications
You must be signed in to change notification settings - Fork 19.9k
/
Copy pathBoundaryFillTest.java
66 lines (49 loc) · 2.25 KB
/
BoundaryFillTest.java
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
package com.thealgorithms.dynamicprogramming;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
public class BoundaryFillTest {
private int[][] image;
@BeforeEach
void setUp() {
image = new int[][] {{0, 0, 0, 0, 0, 0, 0}, {0, 3, 3, 3, 3, 0, 0}, {0, 3, 0, 0, 3, 0, 0}, {0, 3, 0, 0, 3, 3, 3}, {0, 3, 3, 3, 0, 0, 3}, {0, 0, 0, 3, 0, 0, 3}, {0, 0, 0, 3, 3, 3, 3}};
}
@Test
void testGetPixel() {
assertEquals(3, BoundaryFill.getPixel(image, 1, 1));
assertEquals(0, BoundaryFill.getPixel(image, 2, 2));
assertEquals(3, BoundaryFill.getPixel(image, 4, 3));
}
@Test
void testPutPixel() {
BoundaryFill.putPixel(image, 2, 2, 5);
assertEquals(5, BoundaryFill.getPixel(image, 2, 2));
BoundaryFill.putPixel(image, 0, 0, 7);
assertEquals(7, BoundaryFill.getPixel(image, 0, 0));
}
@Test
void testBoundaryFill() {
BoundaryFill.boundaryFill(image, 2, 2, 5, 3);
int[][] expectedImage = {{0, 0, 0, 0, 0, 0, 0}, {0, 3, 3, 3, 3, 0, 0}, {0, 3, 5, 5, 3, 0, 0}, {0, 3, 5, 5, 3, 3, 3}, {0, 3, 3, 3, 5, 5, 3}, {0, 0, 0, 3, 5, 5, 3}, {0, 0, 0, 3, 3, 3, 3}};
for (int i = 0; i < image.length; i++) {
assertArrayEquals(expectedImage[i], image[i]);
}
}
@Test
void testBoundaryFillEdgeCase() {
BoundaryFill.boundaryFill(image, 1, 1, 3, 3);
int[][] expectedImage = {{0, 0, 0, 0, 0, 0, 0}, {0, 3, 3, 3, 3, 0, 0}, {0, 3, 0, 0, 3, 0, 0}, {0, 3, 0, 0, 3, 3, 3}, {0, 3, 3, 3, 0, 0, 3}, {0, 0, 0, 3, 0, 0, 3}, {0, 0, 0, 3, 3, 3, 3}};
for (int i = 0; i < image.length; i++) {
assertArrayEquals(expectedImage[i], image[i]);
}
}
@Test
void testBoundaryFillInvalidCoordinates() {
BoundaryFill.boundaryFill(image, -1, -1, 5, 3);
int[][] expectedImage = {{0, 0, 0, 0, 0, 0, 0}, {0, 3, 3, 3, 3, 0, 0}, {0, 3, 0, 0, 3, 0, 0}, {0, 3, 0, 0, 3, 3, 3}, {0, 3, 3, 3, 0, 0, 3}, {0, 0, 0, 3, 0, 0, 3}, {0, 0, 0, 3, 3, 3, 3}};
for (int i = 0; i < image.length; i++) {
assertArrayEquals(expectedImage[i], image[i]);
}
}
}