Example #1
0
    def test_best_route_logs(self):
        with self.assertLogs('backend', level='INFO') as log:
            route = FindRoute('GRU', 'CDG', FILE)
            route.dijkstra()
            route.best_route()

        self.assertIn('best route: GRU - BRC - SCL - ORL - CDG > 40',
                      log.output[0])
Example #2
0
 def test_best_route(self):
     route = FindRoute('GRU', 'CDG', FILE)
     route.dijkstra()
     best_route = route.best_route()
     result_string_expected = (
         f"best route: {route.source} - {' - '.join(route.path)}"
         f" > {route.shortest_distance[route.destination]}")
     self.assertEqual(best_route, result_string_expected)
Example #3
0
    def test_get_route_brc_cdg(self):
        route = FindRoute('BRC', 'CDG', FILE)
        route.dijkstra()
        route.best_route()

        self.assertEqual(route.result, {
            'route': 'BRC - SCL - ORL - CDG',
            'price': 30
        })
Example #4
0
    def test_get_route_gru_cdg(self):
        route = FindRoute('GRU', 'CDG', FILE)
        route.dijkstra()
        route.best_route()

        self.assertEqual(route.result, {
            'route': 'GRU - BRC - SCL - ORL - CDG',
            'price': 40
        })
Example #5
0
    def test_get_route_brc_cdg_with_lowercase(self):
        route = FindRoute('brc', 'cdg', FILE)
        route.dijkstra()
        route.best_route()

        self.assertEqual(route.result, {
            'route': 'BRC - SCL - ORL - CDG',
            'price': 30
        })
Example #6
0
    def get_route(self):
        route = FindRoute(
            self.route_data['query_params']['source'].upper(),
            self.route_data['query_params']['destination'].upper(),
            self.data
        )
        route.dijkstra()
        route.best_route()

        result = {
            'route': f"{route.source} - {' - '.join(route.path)}",
            'price': route.price
        }

        return result
Example #7
0
 def test_dijkstra_calculate_route(self):
     route = FindRoute('GRU', 'CDG', FILE)
     route.dijkstra()
     self.assertEqual(route.unseen_nodes, {})
     self.assertEqual(route.shortest_distance, {
         'GRU': 0,
         'BRC': 10,
         'SCL': 15,
         'CDG': 40,
         'ORL': 35
     })
     self.assertEqual(route.predecessor, {
         'BRC': 'GRU',
         'CDG': 'ORL',
         'SCL': 'BRC',
         'ORL': 'SCL'
     })
Example #8
0
    def test_get_route_without_file(self):
        route = FindRoute('brc', 'cdg')
        route.dijkstra()
        route.best_route()

        self.assertEqual(route.result, {})
Example #9
0
    def test_get_route_without_destination(self):
        route = FindRoute('brc', '', FILE)
        route.dijkstra()
        route.best_route()

        self.assertEqual(route.result, {})
Example #10
0
    def test_get_route_without_source(self):
        route = FindRoute('', 'cdg', FILE)
        route.dijkstra()
        route.best_route()

        self.assertEqual(route.result, {})