Skip to content

Commit

Permalink
Test updates (#1847)
Browse files Browse the repository at this point in the history
* Test updates

* [pre-commit.ci lite] apply automatic fixes

---------

Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
  • Loading branch information
springfall2008 and pre-commit-ci-lite[bot] authored Jan 5, 2025
1 parent 3747e6d commit d52bfda
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions apps/predbat/unit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4243,6 +4243,7 @@ def run_optimise_all_windows_tests(my_predbat):
price = 16 - n % 16
charge_window_best.append({"start": my_predbat.minutes_now + 30 * n, "end": my_predbat.minutes_now + 30 * (n + 1), "average": price})
expect_charge_limit.append(10 if price <= 5.0 else 0)
expect_charge_limit[26] = 0.5 # freeze
expect_charge_limit[42] = 0.5 # freeze
failed |= run_optimise_all_windows(
"created2",
Expand All @@ -4251,7 +4252,7 @@ def run_optimise_all_windows_tests(my_predbat):
expect_charge_limit=expect_charge_limit,
load_amount=0.2,
pv_amount=0,
expect_best_price=39.7,
expect_best_price=40.3,
inverter_loss=0.9,
best_soc_keep=0.0,
battery_size=10,
Expand All @@ -4261,15 +4262,16 @@ def run_optimise_all_windows_tests(my_predbat):
return failed

# One extra charge as we will fall below keep otherwise
expect_charge_limit[10] = 10.0
expect_charge_limit[9] = 0.5
expect_charge_limit[10] = 1
failed |= run_optimise_all_windows(
"created3",
my_predbat,
charge_window_best=charge_window_best,
expect_charge_limit=expect_charge_limit,
load_amount=0.2,
pv_amount=0,
expect_best_price=31.2,
expect_best_price=29.5,
inverter_loss=0.9,
best_soc_keep=1,
battery_soc=2,
Expand All @@ -4288,14 +4290,17 @@ def run_optimise_all_windows_tests(my_predbat):
charge_window_best.append({"start": my_predbat.minutes_now + 30 * n, "end": my_predbat.minutes_now + 30 * (n + 1), "average": price})
expect_charge_limit.append(10 if price <= 5.0 else 0)

expect_charge_limit[6] = 0.5
expect_charge_limit[22] = 0.5
expect_charge_limit[38] = 0.5
failed |= run_optimise_all_windows(
"created4",
my_predbat,
charge_window_best=charge_window_best,
expect_charge_limit=expect_charge_limit,
load_amount=0.2,
pv_amount=0,
expect_best_price=27,
expect_best_price=28.8,
inverter_loss=0.9,
best_soc_keep=1,
battery_soc=2,
Expand All @@ -4318,8 +4323,8 @@ def run_optimise_all_windows_tests(my_predbat):
if (before_best_metric - best_metric) < 0.099:
print("ERROR: Expected best metric to have 0.1 skew for charging but got {} vs {} skew was {}".format(best_metric, before_best_metric, before_best_metric - best_metric))
failed = True
if best_cost != 27:
print("ERROR: Expected best cost to be 27 but got {}".format(best_cost))
if best_cost != 28.8:
print("ERROR: Expected best cost to be 28.8 but got {}".format(best_cost))
failed = True
my_predbat.isCharging = False

Expand Down

0 comments on commit d52bfda

Please sign in to comment.