-
Notifications
You must be signed in to change notification settings - Fork 19.9k
/
Copy pathMidpointEllipseTest.java
99 lines (92 loc) · 3.84 KB
/
MidpointEllipseTest.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
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
96
97
98
99
package com.thealgorithms.geometry;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.List;
import java.util.stream.Stream;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
/**
* The {@code MidpointEllipseTest} class contains unit tests for the
* {@code MidpointEllipse} class, specifically testing the
* {@code drawEllipse} method.
*
* <p>This class uses parameterized tests to validate the output of
* Midpoint Ellipse algorithm for various input points.</p>
*/
class MidpointEllipseTest {
/**
* Provides test cases for the drawEllipse method.
* Each argument contains: centerX, centerY, a, b, and expected points.
*
* @return a stream of arguments for parameterized testing
*/
static Stream<Arguments> ellipseTestProvider() {
return Stream.of(
Arguments.of(0, 0, 5, 3, new int[][] {{0, 3}, {0, 3}, {0, -3}, {0, -3}, {1, 3}, {-1, 3}, {1, -3}, {-1, -3}, {2, 3}, {-2, 3}, {2, -3}, {-2, -3}, {3, 2}, {-3, 2}, {3, -2}, {-3, -2}, {4, 2}, {-4, 2}, {4, -2}, {-4, -2}, {5, 1}, {-5, 1}, {5, -1}, {-5, -1}, {5, 0}, {-5, 0}, {5, 0}, {-5, 0}}),
Arguments.of(0, 0, 0, 5,
new int[][] {
{0, -5}, {0, -4}, {0, -3}, {0, -2}, {0, -1}, {0, 0}, {0, 1}, {0, 2}, {0, 3}, {0, 4}, {0, 5} // Only vertical line points and center
}),
Arguments.of(0, 0, 5, 0,
new int[][] {
{-5, 0}, {-4, 0}, {-3, 0}, {-2, 0}, {-1, 0}, {0, 0}, {1, 0}, {2, 0}, {3, 0}, {4, 0}, {5, 0} // Only horizontal line points and center
}),
Arguments.of(0, 0, 0, 0,
new int[][] {
{0, 0} // Only center point
}),
Arguments.of(0, 0, 4, 4,
new int[][] {
{0, 4},
{0, 4},
{0, -4},
{0, -4},
{1, 4},
{-1, 4},
{1, -4},
{-1, -4},
{2, 3},
{-2, 3},
{2, -3},
{-2, -3},
{3, 3},
{-3, 3},
{3, -3},
{-3, -3},
{3, 2},
{-3, 2},
{3, -2},
{-3, -2},
{4, 1},
{-4, 1},
{4, -1},
{-4, -1},
{4, 0},
{-4, 0},
{4, 0},
{-4, 0},
}));
}
/**
* Tests the drawEllipse method with various parameters.
*
* @param centerX the x-coordinate of the center of the ellipse
* @param centerY the y-coordinate of the center of the ellipse
* @param a the length of the semi-major axis
* @param b the length of the semi-minor axis
* @param expectedPoints the expected points forming the ellipse
*/
@ParameterizedTest
@MethodSource("ellipseTestProvider")
@DisplayName("Test drawing ellipses with various parameters")
void testDrawEllipse(int centerX, int centerY, int a, int b, int[][] expectedPoints) {
List<int[]> points = MidpointEllipse.drawEllipse(centerX, centerY, a, b);
// Validate the number of points and the specific points
assertEquals(expectedPoints.length, points.size(), "Number of points should match expected.");
for (int i = 0; i < expectedPoints.length; i++) {
assertArrayEquals(expectedPoints[i], points.get(i), "Point mismatch at index " + i);
}
}
}