Skip to content
Snippets Groups Projects
test_osm_charge.py 1.18 KiB
Newer Older
markn92's avatar
markn92 committed
import os

import networkx as nx

markn92's avatar
markn92 committed
from evrouting.osm import read_osm, insert_charging_stations
from evrouting.graph_tools import CHARGING_COEFFICIENT_KEY
markn92's avatar
markn92 committed


markn92's avatar
markn92 committed
def _test_read_osm():
    """Just check if it runs. Todo: Delete."""
    assert read_osm(os.path.join(os.path.dirname(__file__), 'static/map.osm'))


def test_insert_charging_stations_close():
    G = nx.DiGraph()

    # Add two nodes, that exist in osm test map
    G.add_node(0, lat=51.7705832, lon=7.0002595)
    G.add_node(1, lat=51.7696529, lon=6.9568520)

    # Close two node 1
    S = [{"lon": 7.0002593, "lat": 51.7705832, "power": 22.0}]

    G = insert_charging_stations(G, S)

    assert G.nodes[0][CHARGING_COEFFICIENT_KEY] == 22.0
    assert CHARGING_COEFFICIENT_KEY not in G.nodes[1]


def test_insert_charging_stations_eq():
    G = nx.DiGraph()

    # Add two nodes, that exist in osm test map
    G.add_node(0, lat=51.7705832, lon=7.0002595)
    G.add_node(1, lat=51.7696529, lon=6.9568520)

    # Close exactly at node 1
    S = [{"lon": 7.0002595, "lat": 51.7705832, "power": 22.0}]

    G = insert_charging_stations(G, S)

    assert G.nodes[0][CHARGING_COEFFICIENT_KEY] == 22.0
    assert CHARGING_COEFFICIENT_KEY not in G.nodes[1]