コード例 #1
0
    def test_find_nearest_with_one_circle_point(self):
        distance_matrix = DistanceMatrix()

        distance_matrix.add_distance(3.8, 'blue')

        result = distance_matrix.find_nearest_label(k=1)
        expected = ['blue']

        self.assertEqual(expected, result)
コード例 #2
0
    def test_find_nearest_with_two_identical_labels(self):
        distance_matrix = DistanceMatrix()

        distance_matrix.add_distance(3.8, 'blue')
        distance_matrix.add_distance(3, 'blue')

        result = distance_matrix.find_nearest_label(k=3)
        expected = ['blue']

        self.assertEqual(expected, result)
コード例 #3
0
    def test_find_nearest_with_same_label(self):
        distance_matrix = DistanceMatrix()

        distance_matrix.add_distance(3.8, 'blue')
        distance_matrix.add_distance(3.8, 'blue')

        result = distance_matrix.find_nearest_label(k=1)
        expected = ['blue']

        self.assertEqual(sorted(expected), sorted(result))
コード例 #4
0
    def test_find_nearest_point_between_two(self):
        distance_matrix = DistanceMatrix()

        distance_matrix.add_distance(3.8, 'red')
        distance_matrix.add_distance(3, 'blue')

        result = distance_matrix.find_nearest_label(k=1)
        expected = ['blue']

        self.assertEqual(expected, result)
コード例 #5
0
    def test_find_most_present_label_between_three(self):
        distance_matrix = DistanceMatrix()

        distance_matrix.add_distance(3.8, 'red')
        distance_matrix.add_distance(3.8, 'red')
        distance_matrix.add_distance(3, 'blue')

        result = distance_matrix.find_nearest_label(k=3)
        expected = ['red']

        self.assertEqual(expected, result)
コード例 #6
0
    def test_find_most_present_ambigous_labels_between_four(self):
        distance_matrix = DistanceMatrix()

        distance_matrix.add_distance(3.8, 'red')
        distance_matrix.add_distance(3.8, 'red')
        distance_matrix.add_distance(3, 'blue')
        distance_matrix.add_distance(3, 'blue')

        result = distance_matrix.find_nearest_label(k=3)
        expected = ['blue', 'red']

        self.assertEqual(sorted(expected), sorted(result))
コード例 #7
0
    def test_return_only_the_minimal_necessary_point(self):
        distance_matrix = DistanceMatrix()

        distance_matrix.add_distance(2, 'blue')
        distance_matrix.add_distance(3, 'green')
        distance_matrix.add_distance(4, 'blue')
        distance_matrix.add_distance(4, 'green')
        distance_matrix.add_distance(4, 'red')

        result = distance_matrix.find_nearest_label(k=3)
        expected = ['blue', 'green']

        self.assertEqual(sorted(expected), sorted(result))