Exemplo n.º 1
0
    def test_salesman_sort(self):

        long_locations = []
        long_locations.append(Location("A", 10, 10))
        long_locations.append(Location("B", 10, 40))

        short_locations = []
        short_locations.append(Location("A", 10, 10))
        short_locations.append(Location("B", 10, 20))
        
        salesmen = []
        salesmen.append(Salesman(long_locations))
        salesmen.append(Salesman(short_locations))

        # Assert they are in reverse order
        self.assertEqual(salesmen[0].calculate_fitness(), 30)
        self.assertEqual(salesmen[1].calculate_fitness(), 10)

        solution = Solution()
        solution.sort_salesmen(salesmen)

        # Assert they have been sorted
        self.assertEqual(salesmen[0].calculate_fitness(), 10)
        self.assertEqual(salesmen[1].calculate_fitness(), 30)