Skip to content
Snippets Groups Projects
test_charge_routing.py 2.62 KiB
Newer Older
markn92's avatar
markn92 committed
from evrouting.charge import shortest_path

from ..config import (
    edge_case,
    edge_case_start_node_no_cs,
markn92's avatar
markn92 committed
    edge_case_a_slow,
markn92's avatar
markn92 committed
    init_config
)


markn92's avatar
markn92 committed
class TestRoutes:
markn92's avatar
markn92 committed

markn92's avatar
markn92 committed
    def test_shortest_path_charge_at_s_and_a(self):
        """Charging at s."""
markn92's avatar
markn92 committed
        result = shortest_path(**init_config(edge_case))
markn92's avatar
markn92 committed

markn92's avatar
markn92 committed
        assert result['trip_time'] == 3.5
        assert result['path'] == [(0, 0), (0, 1), (1, 2), (1, 2.5), (2, 3.5)]
markn92's avatar
markn92 committed

markn92's avatar
markn92 committed
    def test_shortest_path_charge_at_s_only(self):
        """Charging at s."""
markn92's avatar
markn92 committed
        result = shortest_path(**init_config(edge_case_a_slow))
markn92's avatar
markn92 committed

markn92's avatar
markn92 committed
        assert result['trip_time'] == 3
        assert result['path'] == [(0, 0), (0, 2), (2, 3)]
markn92's avatar
markn92 committed

markn92's avatar
markn92 committed
    def test_shortest_path_no_charge_s_path_t(self):
        """No charging at s but enough initial SoC to go to t directly."""
        conf = init_config(edge_case_start_node_no_cs)
        conf['initial_soc'] = 4
markn92's avatar
markn92 committed
        result = shortest_path(**conf)
markn92's avatar
markn92 committed

markn92's avatar
markn92 committed
        assert result['trip_time'] == 1
        assert result['path'] == [(0, 0), (2, 1)]
markn92's avatar
markn92 committed

markn92's avatar
markn92 committed
    def test_shortest_path_no_charge_s_path_a(self):
        """No charging at s but just enough SoC to go to t via a."""
        conf = init_config(edge_case_start_node_no_cs)
        conf['initial_soc'] = 2
markn92's avatar
markn92 committed
        result = shortest_path(**conf)
markn92's avatar
markn92 committed

markn92's avatar
markn92 committed
        assert result['trip_time'] == 2
        assert result['path'] == [(0, 0), (1, 1), (2, 2)]
markn92's avatar
markn92 committed
class TestWithFinalSoC:

    def test_shortest_path_charge_at_s_and_a(self):
        """Charging at s."""
        conf = init_config(edge_case)
        conf['final_soc'] = 3
markn92's avatar
markn92 committed
        result = shortest_path(**conf)
markn92's avatar
markn92 committed

markn92's avatar
markn92 committed
        assert result['trip_time'] == 5
        assert result['path'] == [(0, 0), (0, 1), (1, 2), (1, 4), (2, 5)]
markn92's avatar
markn92 committed

markn92's avatar
markn92 committed
    def test_path_impossilbe(self):
        """Not possible to end with full battery."""
        conf = init_config(edge_case)
        conf['final_soc'] = 4
markn92's avatar
markn92 committed
        result = shortest_path(**conf)
markn92's avatar
markn92 committed

markn92's avatar
markn92 committed
        assert result['trip_time'] is None
        assert result['path'] == []
markn92's avatar
markn92 committed

markn92's avatar
markn92 committed
    def test_shortest_path_charge_at_s_only(self):
        """Charging at s and a to reach final_soc."""
        conf = init_config(edge_case_a_slow)
        conf['final_soc'] = 3
markn92's avatar
markn92 committed
        result = shortest_path(**conf)
markn92's avatar
markn92 committed

markn92's avatar
markn92 committed
        assert result['trip_time'] == 5
        assert result['path'] == [(0, 0), (0, 2), (1, 3), (1, 4), (2, 5)]
markn92's avatar
markn92 committed

    def test_shortest_path_no_charge_s_path_t(self):
        """No charging at s but initial soc."""
        conf = init_config(edge_case_start_node_no_cs)
        conf['initial_soc'] = 4
        conf['final_soc'] = 3
markn92's avatar
markn92 committed
        result = shortest_path(**conf)

        assert result['trip_time'] == 2.5
        assert result['path'] == [(0, 0), (1, 1), (1, 1.5), (2, 2.5)]
markn92's avatar
markn92 committed