Skip to content
Snippets Groups Projects
Commit bf73f7e6 authored by markn92's avatar markn92
Browse files

test further

parent 59cd815c
No related branches found
No related tags found
No related merge requests found
import pytest import pytest
from evrouting.charge.T import SoCProfile, SoCFunction, ChargingFunction, Label from evrouting.charge.T import SoCProfile, SoCFunction, ChargingFunction, Label
from itertools import count
@pytest.fixture @pytest.fixture
...@@ -26,6 +27,17 @@ def ch_function(): ...@@ -26,6 +27,17 @@ def ch_function():
return c, capacity, ChargingFunction(c, capacity) return c, capacity, ChargingFunction(c, capacity)
@pytest.fixture
def ch_function_fast():
c = 3
capacity = 4
return c, capacity, ChargingFunction(c, capacity)
last_cs_generator = count()
@pytest.fixture @pytest.fixture
def label(soc_profile_2): def label(soc_profile_2):
_, _, profile = soc_profile_2 _, _, profile = soc_profile_2
...@@ -33,7 +45,7 @@ def label(soc_profile_2): ...@@ -33,7 +45,7 @@ def label(soc_profile_2):
t_trip=10, t_trip=10,
soc_last_cs=2, soc_last_cs=2,
soc_profile_cs_v=profile, soc_profile_cs_v=profile,
last_cs=1 last_cs=next(last_cs_generator)
) )
...@@ -41,3 +53,9 @@ def label(soc_profile_2): ...@@ -41,3 +53,9 @@ def label(soc_profile_2):
def soc_function(label, ch_function): def soc_function(label, ch_function):
_, _, cf = ch_function _, _, cf = ch_function
return SoCFunction(label, cf) return SoCFunction(label, cf)
@pytest.fixture
def soc_function_fast(label, ch_function_fast):
_, _, cf = ch_function_fast
return SoCFunction(label, cf)
...@@ -111,6 +111,9 @@ class TestSoCFunction: ...@@ -111,6 +111,9 @@ class TestSoCFunction:
assert soc_function._calc_minimum() == -inf assert soc_function._calc_minimum() == -inf
def test_dominance(self, soc_function, soc_function_fast):
assert soc_function_fast.dominates(soc_function)
class TestChargingFunction: class TestChargingFunction:
def test_creation(self, ch_function): def test_creation(self, ch_function):
......
import pytest import pytest
from copy import copy
from evrouting.charge.utils import LabelPriorityQueue from evrouting.charge.utils import LabelPriorityQueue
from evrouting.charge.T import Label from evrouting.charge.T import Label
from evrouting.charge.factories import SoCFunctionFactory from evrouting.charge.factories import SoCFunctionFactory, ChargingFunctionMap
@pytest.fixture @pytest.fixture
def q(label, ch_function): def q(label, ch_function):
_, _, cf = ch_function _, _, cf = ch_function
dummy_cf = {label.last_cs: cf} dummy_cf = {label.last_cs: cf}
q = LabelPriorityQueue(SoCFunctionFactory(dummy_cf), l_set=set({})) q = LabelPriorityQueue(SoCFunctionFactory(dummy_cf), l_set=[])
q.insert(label) q.insert(label)
# create min # create min
...@@ -43,3 +44,30 @@ class TestProrityQueue: ...@@ -43,3 +44,30 @@ class TestProrityQueue:
label = q.peak_min() label = q.peak_min()
q.remove_item(label) q.remove_item(label)
q.insert(label) q.insert(label)
def test_dominance_check(self, label, soc_function, soc_function_fast):
label_fast = Label(
t_trip=label.t_trip,
soc_last_cs=label.soc_last_cs,
last_cs=2,
soc_profile_cs_v=label.soc_profile_cs_v,
)
cf = {
label.last_cs: soc_function.cf_cs,
label_fast.last_cs: soc_function_fast.cf_cs
}
f_soc = SoCFunctionFactory(cf=cf)
# minimum is dominated by lset
l_set = [label, label_fast]
queue = LabelPriorityQueue(f_soc=f_soc, l_set=l_set)
queue.insert(label)
assert not queue
# minimum is not dominated by lset
l_set = [label]
queue = LabelPriorityQueue(f_soc=f_soc, l_set=l_set)
queue.insert(label_fast)
assert queue
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment