Skip to content

Commit

Permalink
fix test + add new case
Browse files Browse the repository at this point in the history
Signed-off-by: Victor Garcia Reolid <victor@seita.nl>
  • Loading branch information
victorgarcia98 committed Dec 12, 2023
1 parent 5e940f2 commit 06c41ac
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
6 changes: 5 additions & 1 deletion flexmeasures/data/models/planning/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,17 @@ def process(db, building, setup_sources) -> dict[str, Sensor]:
def add_stock_gain(db, add_battery_assets, setup_sources) -> dict[str, Sensor]:
"""
Set up the same constant gain (-capacity_in_mw) in different resolutions.
In 15 min event resolution, the maximum energy that the battery can produce/consume in period
is 0.25 * capacity_in_mw
"""

battery = add_battery_assets["Test battery"]
capacity = battery.get_attribute("capacity_in_mw")
sensors = {}
sensor_specs = [
("gain", timedelta(minutes=15), capacity, True),
("gain fails", timedelta(minutes=15), capacity, True),
("gain", timedelta(minutes=15), capacity * 0.25, True),
("gain hourly", timedelta(hours=1), capacity, True),
("gain None", timedelta(hours=1), -capacity, None),
("gain consumption is negative", timedelta(hours=1), -capacity, False),
Expand Down
14 changes: 7 additions & 7 deletions flexmeasures/data/models/planning/tests/test_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -1452,7 +1452,7 @@ def test_battery_power_capacity_as_sensor(

@pytest.mark.parametrize(
"stock_gain_sensor",
["gain", "gain hourly", "gain None", "gain consumption is negative"],
["gain fails", "gain", "gain hourly", "gain None", "gain consumption is negative"],
)
def test_battery_stock_gain_sensor(
add_battery_assets, add_stock_gain, stock_gain_sensor
Expand Down Expand Up @@ -1489,13 +1489,13 @@ def test_battery_stock_gain_sensor(
"soc-at-start": 0,
},
)
stock_gain_constraint = scheduler._prepare()[5][0]["stock gain"]

assert all(stock_gain_constraint == -capacity)

schedule = scheduler.compute()

assert all(schedule == capacity)
if "fails" in stock_gain_sensor:
with pytest.raises(InfeasibleProblemException):
schedule = scheduler.compute()
else:
schedule = scheduler.compute()
assert all(schedule == capacity)


@pytest.mark.parametrize(
Expand Down

0 comments on commit 06c41ac

Please sign in to comment.