Files
EOS/tests/test_class_optimize.py
T

35 lines
1.1 KiB
Python
Raw Normal View History

2024-10-06 18:16:43 +02:00
import json
from pathlib import Path
2024-10-04 19:03:41 +02:00
import pytest
2024-10-06 12:33:18 +02:00
from akkudoktoreos.class_optimize import optimization_problem
2024-10-04 19:03:41 +02:00
2024-10-06 18:16:43 +02:00
DIR_TESTDATA = Path(__file__).parent / "testdata"
2024-10-04 19:03:41 +02:00
2024-10-06 18:16:43 +02:00
@pytest.mark.parametrize(
"fn_in, fn_out", [("optimize_input_1.json", "optimize_result_1.json")]
)
@pytest.mark.skip(reason="Expensive - Skipped per default")
def test_optimize(fn_in, fn_out):
# Load input and output data
with open(DIR_TESTDATA / fn_in, "r") as f_in:
input_data = json.load(f_in)
2024-10-04 19:03:41 +02:00
2024-10-06 18:16:43 +02:00
with open(DIR_TESTDATA / fn_out, "r") as f_out:
expected_output_data = json.load(f_out)
2024-10-04 19:03:41 +02:00
opt_class = optimization_problem(
prediction_hours=48, strafe=10, optimization_hours=24, fixed_seed=42
)
2024-10-06 18:16:43 +02:00
start_hour = 10
2024-10-04 19:03:41 +02:00
# Call the optimization function
2024-10-06 18:16:43 +02:00
ergebnis = opt_class.optimierung_ems(parameter=input_data, start_hour=start_hour)
2024-10-04 19:03:41 +02:00
2024-10-06 18:16:43 +02:00
# Assert that the output contains all expected entries.
# This does not assert that the optimization always gives the same result!
# Reproducibility and mathematical accuracy should be tested on the level of individual components.
assert set(ergebnis) == set(expected_output_data)