def test_points_selection_04(self): number_of_samples = 5 x = np.array([[8.79], [0.35], [4.56]]) data_feed = CVTSampling(self.test_data, number_of_samples) output = data_feed.points_selection(self.test_data.values, x) expected_output = np.array([[9., 100.], [0., 1.], [5., 36.]]) self.assertEqual(output.tolist(), expected_output.tolist())
def test_initialization_05(self): output_2 = CVTSampling(self.test_data) expected_output = 5 expected_output_2 = np.array([[0], [1], [2], [3], [4], [5], [6], [7], [8], [9]]) self.assertEqual(output_2.number_of_centres, expected_output) self.assertEqual(output_2.x_data.tolist(), expected_output_2.tolist())
def test_create_centres_03(self): initial_centres = np.array([[0, 0], [1, 1]]) current_random_points = np.array([[0.6, 0.6], [0.8, 0.8]]) current_centres = np.array([1, 1]) counter = 5 expected_output = np.array([[0.5 / 6, 0.5 / 6], [5.7 / 6, 5.7 / 6]]) output = CVTSampling.create_centres(initial_centres, current_random_points, current_centres, counter) np.testing.assert_array_equal(expected_output, output)
def test_create_centres_02(self): initial_centres = np.array([[0, 0], [1, 1]]) current_random_points = np.array([[0.6, 0.6], [0.3, 0.3]]) current_centres = np.array([1, 0]) counter = 10 expected_output = np.array([[0.3 / 11, 0.3 / 11], [10.6 / 11, 10.6 / 11]]) output = CVTSampling.create_centres(initial_centres, current_random_points, current_centres, counter) np.testing.assert_array_equal(expected_output, output)
def test_create_centres_04(self): initial_centres = np.array([[0, 0, 0], [1, 1, 1]]) current_random_points = np.array([[0.1, 0.1, 0.1], [0.3, 0.3, 0.3], [0.5, 0.5, 0.5], [0.7, 0.7, 0.7], [0.9, 0.9, 0.9]]) current_centres = np.array([0, 0, 0, 1, 1]) counter = 4 expected_output = np.array([[0.3 / 5, 0.3 / 5, 0.3 / 5], [4.8 / 5, 4.8 / 5, 4.8 / 5]]) output = CVTSampling.create_centres(initial_centres, current_random_points, current_centres, counter) np.testing.assert_array_equal(expected_output, output)
def test_eucl_distance_04(self): u = np.array([[1, 2]]) v = np.array([[5, 6], [7, 8]]) expected_output = np.array([32**0.5, 72**0.5]) output = CVTSampling.eucl_distance(u, v) np.testing.assert_array_equal(expected_output, output)
def test_eucl_distance_02(self): u = np.array([[1, 2]]) v = np.array([[3, 4]]) expected_output = 8**0.5 output = CVTSampling.eucl_distance(u, v) self.assertEqual(expected_output, output)
def test_eucl_distance_01(self): u = np.array([[3]]) v = np.array([[5]]) expected_output = 2 output = CVTSampling.eucl_distance(u, v) self.assertEqual(expected_output, output)
def test_initialization_14(self): with self.assertRaises(Exception): CVTSampling(self.test_data, tolerance='0.1')
def test_initialization_13(self): tol = 1e-9 output = CVTSampling(self.test_data, tolerance=tol) self.assertEqual(output.eps, tol)
def test_initialization_12(self): deft = 1e-07 output = CVTSampling(self.test_data) self.assertEqual(output.eps, deft)
def test_initialization_08(self): test_data_as_list = self.test_data.values.tolist() with self.assertRaises(ValueError): CVTSampling(test_data_as_list, 7)
def test_initialization_07(self): test_data_as_array = self.test_data.values output_1 = CVTSampling(test_data_as_array, 7) np.testing.assert_array_equal(output_1.data, test_data_as_array)
def test_initialization_06(self): with self.assertRaises(Exception): CVTSampling(self.test_data, 1.7)