1
+ package com .thealgorithms .geometry ;
2
+
3
+ import java .awt .Point ;
4
+ import java .util .Collection ;
5
+ import java .util .List ;
6
+ import java .util .stream .Stream ;
7
+ import org .junit .jupiter .api .Assertions ;
8
+ import org .junit .jupiter .params .ParameterizedTest ;
9
+ import org .junit .jupiter .params .provider .Arguments ;
10
+ import org .junit .jupiter .params .provider .MethodSource ;
11
+
12
+ /**
13
+ * The {@code MidpointCircleTest} class contains unit tests for the
14
+ * {@code MidpointCircle} class, specifically testing the
15
+ * {@code drawCircle} method.
16
+ *
17
+ * <p>This class uses parameterized tests to validate the output of
18
+ * the Midpoint Circle algorithm for various input parameters.</p>
19
+ */
20
+ class MidpointCircleTest {
21
+
22
+ /**
23
+ * Provides test cases for the parameterized test.
24
+ *
25
+ * <p>Each test case includes center coordinates, radius,
26
+ * and the expected collection of points that should be generated by the
27
+ * {@code drawCircle} method.</p>
28
+ *
29
+ * @return a stream of arguments containing test cases
30
+ */
31
+ static Stream <Arguments > circlePointsProvider () {
32
+ return Stream .of (
33
+ Arguments .of (0 , 0 , 1 , List .of (new Point (0 , 1 ), new Point (1 , 0 ), new Point (0 , -1 ), new Point (-1 , 0 ), new Point (1 , 1 ), new Point (-1 , -1 ), new Point (1 , -1 ), new Point (-1 , 1 ))),
34
+ Arguments .of (0 , 0 , 2 , List .of (new Point (0 , 2 ), new Point (2 , 0 ), new Point (0 , -2 ), new Point (-2 , 0 ), new Point (2 , 2 ), new Point (-2 , -2 ), new Point (2 , -2 ), new Point (-2 , 2 ))),
35
+ Arguments .of (1 , 1 , 3 , List .of (new Point (1 , 4 ), new Point (4 , 1 ), new Point (1 , -2 ), new Point (-2 , 1 ), new Point (4 , 4 ), new Point (-2 , -2 ), new Point (4 , -2 ), new Point (-2 , 4 ))),
36
+ Arguments .of (-3 , -3 , 4 , List .of (new Point (-3 , 1 ), new Point (1 , -3 ), new Point (-3 , -7 ), new Point (-7 , -3 ), new Point (1 , 1 ), new Point (-7 , -7 ), new Point (1 , -7 ), new Point (-7 , 1 )))
37
+ );
38
+ }
39
+
40
+ /**
41
+ * Tests the {@code drawCircle} method of the {@code MidpointCircle} class.
42
+ *
43
+ * <p>This parameterized test runs multiple times with different sets of
44
+ * center coordinates and radii to validate that the generated points
45
+ * match the expected output.</p>
46
+ *
47
+ * @param xc the x-coordinate of the center point
48
+ * @param yc the y-coordinate of the center point
49
+ * @param r the radius of the circle
50
+ * @param expected a collection of expected points that should form a circle
51
+ */
52
+ @ ParameterizedTest
53
+ @ MethodSource ("circlePointsProvider" )
54
+ void testDrawCircle (int xc , int yc , int r , Collection <Point > expected ) {
55
+ List <Point > actual = MidpointCircle .drawCircle (xc , yc , r );
56
+ Assertions .assertEquals (expected .size (), actual .size (), "The size of the points list should match." );
57
+ Assertions .assertTrue (expected .containsAll (actual ) && actual .containsAll (expected ), "The points generated should match the expected points." );
58
+ }
59
+ }
0 commit comments