Beispiel #1
0
    def test_nothing_to_do(self):
        #GIVEN no requests and no passengers
        city_state = CityState(8, 8)
        request = []

        #WHEN I increment time
        city_state.increment_time(request)

        #THEN the next destination does not change
        self.assertEqual(city_state.car.get_location(), (0, 0))
        self.assertEqual(city_state.get_next_destination(),
                         Destination((0, 0), 0, None))
Beispiel #2
0
    def test_prefer_close_small_cluster_if_larger_cluster_is_very_far(
            self, city_x, city_y, close_seed_value, far_seed_value):
        #GIVEN a set of clustered requests, 1 of which is close and 1 of which is very far
        city_state = CityState(city_x, city_y)
        dummy_end_locale = (8, 8)
        individual = [{'name': 'Queequeg', 'start': (2, 10), 'end': (40, 10)}]

        expected_next_destination = (close_seed_value, close_seed_value + 1)
        closer_cluster = [{
            'name': 'McCavity',
            'start': expected_next_destination,
            'end': dummy_end_locale
        }, {
            'name': 'Mistoffoles',
            'start': (close_seed_value, close_seed_value + 2),
            'end': dummy_end_locale
        }]

        distant_large_cluster = [{
            'name': 'Ishmael',
            'start': (far_seed_value + 1, city_y - 1),
            'end': dummy_end_locale
        }, {
            'name': 'Mieville',
            'start': (far_seed_value, city_y - 1),
            'end': dummy_end_locale
        }, {
            'name': 'Starbuck',
            'start': (far_seed_value + 2, city_y - 1),
            'end': dummy_end_locale
        }]

        request = individual + closer_cluster + distant_large_cluster

        #WHEN I decide which destination to choose
        city_state.increment_time(request)

        #THEN it is in the smaller cluster, even though a larger one exists
        next_destination = city_state.get_next_destination()
        self.assertEqual(next_destination.location, expected_next_destination)
Beispiel #3
0
    def test_prefer_larger_clusters_to_smaller(self):
        #GIVEN a set of clustered requests, 1 of which is closer and 1 of which is farther, but larger
        city_state = CityState(50, 50)
        individual = [{'name': 'Queequeg', 'start': (10, 10), 'end': (40, 10)}]

        closer_cluster = [{
            'name': 'McCavity',
            'start': (30, 10),
            'end': (40, 10)
        }, {
            'name': 'Mistoffoles',
            'start': (30, 11),
            'end': (20, 10)
        }]

        closest_large_cluster_location_start = (35, 4)
        farther_larger_cluster = [{
            'name': 'Ishmael',
            'start': closest_large_cluster_location_start,
            'end': (4, 3)
        }, {
            'name': 'Mieville',
            'start': (35, 5),
            'end': (8, 17)
        }, {
            'name': 'Starbuck',
            'start': (35, 6),
            'end': (30, 7)
        }]

        request = individual + closer_cluster + farther_larger_cluster

        #WHEN I decide which destination to choose
        city_state.increment_time(request)

        #THEN it is in the larger cluster even though it's further away
        next_destination = city_state.get_next_destination()
        self.assertEqual(next_destination.location,
                         closest_large_cluster_location_start)
Beispiel #4
0
    def test_prefer_clusters_to_individuals(self):
        #GIVEN a set of requests, 1 of which is close and 2 of which are farther, but near each other
        city_state = CityState(50, 50)
        close_person = {'name': 'McCavity', 'start': (10, 10), 'end': (10, 11)}
        closest_cluster_location_start = (25, 4)
        request = [
            close_person, {
                'name': 'Ishmael',
                'start': closest_cluster_location_start,
                'end': (4, 3)
            }, {
                'name': 'Mieville',
                'start': (25, 5),
                'end': (8, 7)
            }
        ]

        #WHEN I decide which destination to choose
        city_state.increment_time(request)

        #THEN it is in the cluster even though it's further away
        next_destination = city_state.get_next_destination()
        self.assertEqual(next_destination.location,
                         closest_cluster_location_start)