From 4d5e4167a8d692f8ca7d032bb739a5203d38dbe8 Mon Sep 17 00:00:00 2001
From: "niehues.mark@gmail.com" <niehues.mark@gmail.com>
Date: Fri, 8 May 2020 21:09:16 +0200
Subject: [PATCH] makes sense so far

---
 tests/osm/test_osm_charge.py | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/tests/osm/test_osm_charge.py b/tests/osm/test_osm_charge.py
index 0a24192..d6aaa80 100644
--- a/tests/osm/test_osm_charge.py
+++ b/tests/osm/test_osm_charge.py
@@ -105,23 +105,35 @@ def test_charge_shortest_route_stop(map_graph):
     cost_path = 6 * consumption * 1000  # distance * consumption in Wh
 
     c = consumption_function_distance_factory(consumption)
-
+    mu_s = 2000
+    mu_t = 0
     result = charge.routing.shortest_path(
         G=map_graph,
         charging_stations=map_graph.charging_stations,
         s=_s,
         t=_t,
-        initial_soc=2000,  # > cost_path
-        final_soc=0,
+        initial_soc=mu_s,  # > cost_path
+        final_soc=mu_t,
         capacity=10000,
         c=c
     )
 
     assert type(result) is Result
-    charge_at = [t for n, t in result.charge_path if t > 0]
+    charge_at = [(n, t) for n, t in result.charge_path if t > 0]
     # charge once
     assert len(charge_at) == 1
 
+    cs, charging_time = charge_at[0]
+    cs_coefficient = map_graph.nodes[cs][CHARGING_COEFFICIENT_KEY]
+
+    nodes = [n for n, _ in result.charge_path]
+    distance = sum([map_graph.edges[u, v][HAVERSINE_KEY]
+                    for u, v in zip(nodes[:-1], nodes[1:])])
+    total_consumption = distance * consumption
+
+    # What has been charged equals what is necessary to reach the goal
+    assert round(total_consumption - mu_s + mu_t) == round(cs_coefficient * charging_time)
+
     # Charge about 10 min
-    assert charge_at[0] < 600
-    assert charge_at[0] > 500
+    assert charging_time < 600
+    assert charging_time > 500
-- 
GitLab