2import numpy.testing
as npt
5 get_average_difference,
6 get_mean_squared_difference,
7 get_inter_cones_distance,
9 build_adjacency_matrix,
16 Test case for the data association methods of the Evaluator class.
21 Set up the test environment by initializing output and ground truth arrays.
31 np.array([2.4, 0.8, 0]),
34 np.array([3.5, 4.3, 0]),
36 np.array([4.3, 3.4, 0])
41 Test the get_average_difference function when both arrays are non-empty.
42 Expects a correct average difference based on manually calculated values.
45 self.assertAlmostEqual(average_difference, 0.7157378651666527, delta=1e-10)
49 Test the get_average_difference function when the output array is empty.
50 Expects infinity as the return value.
52 average_difference = get_average_difference([], self.
ground_truth)
53 self.assertEqual(average_difference, float(
"inf"))
57 Test the get_average_difference function when the ground truth array is empty.
58 Expects a ValueError due to incompatible data.
60 with self.assertRaises(ValueError):
61 get_average_difference(self.
output, [])
65 Test the get_mean_squared_difference function with valid output and ground truth arrays.
66 Expects a mean squared difference close to the manually calculated value.
69 self.assertAlmostEqual(mean_squared_error, 1.03, delta=0.00001)
73 Test the get_inter_cones_distance function for a non-empty output array.
74 Expects a correct average inter-cone distance based on the output array.
76 inter_cones_distance = get_inter_cones_distance(self.
output)
77 self.assertAlmostEqual(inter_cones_distance, 1.6071067811865476, delta=0.005)
81 Test the get_inter_cones_distance function for an empty output array.
82 Expects a zero return value since there are no cones.
84 inter_cones_distance = get_inter_cones_distance(np.array([]))
85 self.assertEqual(inter_cones_distance, 0)
89 Test the get_false_positives function with a threshold of 1.0.
90 Expects the number of false positives based on the given threshold and arrays.
94 self.assertEqual(false_positives, 1)
98 Test the get_false_positives function with arrays swapped and a threshold of 1.0.
99 Expects a different number of false positives when the arrays are swapped.
103 ground_truth = self.
output
104 false_positives = get_false_positives(output, ground_truth, threshold)
105 self.assertEqual(false_positives, 5)
109 Test the get_duplicates function with a threshold of 0.01.
110 Expects no duplicates since the output array does not contain any within this threshold.
113 count = get_duplicates(self.
output, threshold)
114 self.assertEqual(count, 0)
118 Test the get_duplicates function with a threshold of 1.0.
119 Expects 1 duplicate since the ground truth array contains a close match within this threshold.
123 count = get_duplicates(output, threshold)
124 self.assertEqual(count, 1)
128 Test the build_adjacency_matrix function with a subarray of the ground truth array.
129 Expects an adjacency matrix calculated based on pairwise distances.
132 adjacency_matrix = build_adjacency_matrix(subarray)
133 expected = np.array([
134 np.array([0, 1.8439088914585773]),
135 np.array([1.8439088914585773, 0])
137 npt.assert_array_almost_equal(adjacency_matrix, expected, decimal=6)
141 Test the build_adjacency_matrix function with a different subarray of the ground truth array.
142 Expects an adjacency matrix calculated for a different subset of cones.
145 adjacency_matrix = build_adjacency_matrix(subarray)
146 expected = np.array([
147 np.array([0, 2.720294101747089]),
148 np.array([2.720294101747089, 0])
150 npt.assert_array_almost_equal(adjacency_matrix, expected, decimal=6)
test_get_false_positives(self)
test_get_mean_squared_error(self)
test_get_average_difference3(self)
test_get_average_difference1(self)
test_adjacency_matrix2(self)
test_get_false_positives2(self)
test_get_inter_cones_distance2(self)
test_get_duplicates2(self)
test_get_duplicates(self)
test_get_inter_cones_distance(self)
test_get_average_difference2(self)
test_adjacency_matrix(self)