Exemplo n.º 1
0
        def test_calculate_correct_result_with_mocking():
            subject = NearestStationFinder(
                **create_mock_analysis(route_types_to_solve=[1]),
                data=MockData(),
                progress_between_pruning_progress_dict=None,
                prune_thoroughness=None,
                stop_join_string='~~',
                transfer_duration_seconds=None,
                transfer_route=None,
                walk_route=None,
                walk_speed_mph=None)

            expected = 5

            with patch.object(subject,
                              '_find_next_travel_time_secs',
                              return_value=expected) as travel_time_patch:
                actual = subject.travel_time_secs_to_nearest_solution_station(
                    'Wonderland',
                    ['Heath Street', 'Bowdoin', 'Back of the Hill'],
                    DEFAULT_START_TIME)
                self.assertEqual(travel_time_patch.call_count,
                                 5)  # two departures at 7AM

            self.assertEqual(actual, expected)
Exemplo n.º 2
0
 def test_returns_true_if_on_solution_stop():
     subject = NearestStationFinder(
         **create_mock_analysis(route_types_to_solve=[1]),
         data=MockData(),
         progress_between_pruning_progress_dict=None,
         prune_thoroughness=None,
         stop_join_string='~~',
         transfer_duration_seconds=None,
         transfer_route=None,
         walk_route=None,
         walk_speed_mph=None)
     location = LocationStatusInfo(location='Back of the Hill',
                                   unvisited='not a stop',
                                   arrival_route='Blue')
     self.assertTrue(subject._is_solution(location))
Exemplo n.º 3
0
 def test_return_0_for_solution_station():
     subject = NearestStationFinder(
         **create_mock_analysis(route_types_to_solve=[1]),
         data=MockData(),
         progress_between_pruning_progress_dict=None,
         prune_thoroughness=None,
         stop_join_string='~~',
         transfer_duration_seconds=None,
         transfer_route=None,
         walk_route=None,
         walk_speed_mph=None)
     self.assertEqual(
         subject.travel_time_secs_to_nearest_solution_station(
             'Heath Street', ['Heath Street', 'Bowdoin'],
             DEFAULT_START_TIME), 0)
Exemplo n.º 4
0
        def test_calculate_correct_result_without_mocking():
            subject = NearestStationFinder(
                **create_mock_analysis(route_types_to_solve=[1]),
                data=MockData(),
                progress_between_pruning_progress_dict=None,
                prune_thoroughness=None,
                stop_join_string='~~',
                transfer_duration_seconds=60,
                transfer_route='transfer_route',
                walk_route='walk_route',
                walk_speed_mph=1)

            expected = 1200
            actual = subject.travel_time_secs_to_nearest_solution_station(
                'Lechmere', ['Back of the Hill'], DEFAULT_START_TIME)
            self.assertLess(abs(expected - actual), 0.001)
Exemplo n.º 5
0
 def test__find_next_departure_time(self):
     subject = NearestStationFinder(
         **create_mock_analysis(route_types_to_solve=[1]),
         data=MockData(),
         progress_between_pruning_progress_dict=None,
         prune_thoroughness=None,
         stop_join_string='~~',
         transfer_duration_seconds=None,
         transfer_route=None,
         walk_route=None,
         walk_speed_mph=None)
     self.assertEqual(
         subject._find_next_departure_time(
             'Wonderland', DEFAULT_START_TIME + timedelta(hours=5.99)),
         DEFAULT_START_TIME + timedelta(hours=6))
     self.assertEqual(
         subject._find_next_departure_time(
             'Wonderland', DEFAULT_START_TIME + timedelta(hours=6)),
         DEFAULT_START_TIME + timedelta(hours=6))
     self.assertEqual(
         subject._find_next_departure_time(
             'Wonderland', DEFAULT_START_TIME + timedelta(hours=6.01)),
         DEFAULT_START_TIME + timedelta(hours=7))
     self.assertEqual(
         subject._find_next_departure_time(
             'Wonderland', DEFAULT_START_TIME + timedelta(hours=9.01)),
         DEFAULT_START_TIME + timedelta(hours=11))
     self.assertEqual(
         subject._find_next_departure_time(
             'Wonderland', DEFAULT_START_TIME + timedelta(hours=11.01)),
         None)
Exemplo n.º 6
0
    def test__initialize_progress_dict(self):
        subject = NearestStationFinder(
            **create_mock_analysis(route_types_to_solve=[1]),
            data=MockData(),
            progress_between_pruning_progress_dict=None,
            prune_thoroughness=None,
            stop_join_string='~~',
            transfer_duration_seconds=None,
            transfer_route=None,
            walk_route=None,
            walk_speed_mph=None)
        subject._initialize_progress_dict(
            'Wonderland', DEFAULT_START_TIME + timedelta(hours=7))

        expected = {
            LocationStatusInfo(location='Wonderland',
                               arrival_route=1,
                               unvisited='~~any_solution_stop~~'):
            ProgressInfo(duration=0,
                         arrival_trip='3-6AM',
                         children=None,
                         eliminated=False,
                         expanded=False,
                         minimum_remaining_time=0,
                         parent=None,
                         trip_stop_no='2'),
            LocationStatusInfo(location='Wonderland',
                               arrival_route=2,
                               unvisited='~~any_solution_stop~~'):
            ProgressInfo(duration=0,
                         arrival_trip='18-7AM',
                         children=None,
                         eliminated=False,
                         expanded=False,
                         minimum_remaining_time=0,
                         parent=None,
                         trip_stop_no='1')
        }
        actual = subject._progress_dict
        self.assertDictEqual(expected, actual)