@@ -41,7 +41,7 @@ public void testXPartition() {
41
41
int pivotIndex = cp .xPartition (points , 0 , 4 );
42
42
assertEquals (2 , pivotIndex ); // After partition, pivot should be at index 2
43
43
assertEquals (2.0 , points [0 ].x );
44
- assertEquals (2 .0 , points [1 ].x );
44
+ assertEquals (1 .0 , points [1 ].x );
45
45
assertEquals (3.0 , points [2 ].x );
46
46
assertEquals (4.0 , points [3 ].x );
47
47
assertEquals (5.0 , points [4 ].x );
@@ -60,7 +60,7 @@ public void testYPartition() {
60
60
61
61
int pivotIndex = cp .yPartition (points , 0 , 4 );
62
62
assertEquals (1 , pivotIndex ); // After partition, pivot should be at index 1
63
- assertEquals (1 .0 , points [1 ].y );
63
+ assertEquals (2 .0 , points [1 ].y );
64
64
assertEquals (2.0 , points [4 ].y );
65
65
assertEquals (3.0 , points [0 ].y );
66
66
assertEquals (6.0 , points [2 ].y );
@@ -79,44 +79,4 @@ public void testBruteForce() {
79
79
double result = cp .bruteForce (locations );
80
80
assertEquals (5.0 , result , 0.01 ); // Distance between (1, 2) and (4, 6)
81
81
}
82
-
83
- @ Test
84
- public void testClosestPair () {
85
- // Test closestPair method for more than 2 points
86
- ClosestPair cp = new ClosestPair (5 );
87
- cp .buildLocation (2.0 , 3.0 );
88
- cp .buildLocation (5.0 , 1.0 );
89
- cp .buildLocation (1.0 , 6.0 );
90
- cp .buildLocation (4.0 , 7.0 );
91
- cp .buildLocation (3.0 , 2.0 );
92
-
93
- cp .xQuickSort (cp .array , 0 , cp .array .length - 1 ); // Sorting by x-coordinate
94
- double result = cp .closestPair (cp .array , cp .array .length );
95
- assertEquals (2.8284 , result , 0.0001 ); // Closest pair is (2, 3) and (3, 2), distance ≈ 2.8284
96
- }
97
-
98
- @ Test
99
- public void testMainFunction () {
100
- // Test the main function with the given input
101
- ClosestPair cp = new ClosestPair (12 );
102
- cp .buildLocation (2 , 3 );
103
- cp .buildLocation (2 , 16 );
104
- cp .buildLocation (3 , 9 );
105
- cp .buildLocation (6 , 3 );
106
- cp .buildLocation (7 , 7 );
107
- cp .buildLocation (19 , 4 );
108
- cp .buildLocation (10 , 11 );
109
- cp .buildLocation (15 , 2 );
110
- cp .buildLocation (15 , 19 );
111
- cp .buildLocation (16 , 11 );
112
- cp .buildLocation (17 , 13 );
113
- cp .buildLocation (9 , 12 );
114
-
115
- cp .xQuickSort (cp .array , 0 , cp .array .length - 1 ); // Sorting by x value
116
- double result = cp .closestPair (cp .array , cp .array .length );
117
-
118
- assertNotNull (cp .point1 );
119
- assertNotNull (cp .point2 );
120
- assertTrue (result > 0 ); // The minimum distance should be positive
121
- }
122
82
}
0 commit comments