mirror of
https://github.com/Akkudoktor-EOS/EOS.git
synced 2025-08-25 15:01:14 +00:00
Apply isort and ruff code style
This commit is contained in:
@@ -1 +0,0 @@
|
||||
from test_heatpump import heatpump
|
@@ -1,9 +1,9 @@
|
||||
import unittest
|
||||
import numpy as np
|
||||
|
||||
from modules.class_akku import PVAkku
|
||||
|
||||
class TestPVAkku(unittest.TestCase):
|
||||
|
||||
class TestPVAkku(unittest.TestCase):
|
||||
def setUp(self):
|
||||
# Initializing common parameters for tests
|
||||
self.kapazitaet_wh = 10000 # 10,000 Wh capacity
|
||||
@@ -13,54 +13,129 @@ class TestPVAkku(unittest.TestCase):
|
||||
self.max_soc_prozent = 80 # Maximum SoC is 80%
|
||||
|
||||
def test_initial_state_of_charge(self):
|
||||
akku = PVAkku(self.kapazitaet_wh, hours=1, start_soc_prozent=50, min_soc_prozent=self.min_soc_prozent, max_soc_prozent=self.max_soc_prozent)
|
||||
self.assertEqual(akku.ladezustand_in_prozent(), 50.0, "Initial SoC should be 50%")
|
||||
akku = PVAkku(
|
||||
self.kapazitaet_wh,
|
||||
hours=1,
|
||||
start_soc_prozent=50,
|
||||
min_soc_prozent=self.min_soc_prozent,
|
||||
max_soc_prozent=self.max_soc_prozent,
|
||||
)
|
||||
self.assertEqual(
|
||||
akku.ladezustand_in_prozent(), 50.0, "Initial SoC should be 50%"
|
||||
)
|
||||
|
||||
def test_discharge_below_min_soc(self):
|
||||
akku = PVAkku(self.kapazitaet_wh, hours=1, start_soc_prozent=50, min_soc_prozent=self.min_soc_prozent, max_soc_prozent=self.max_soc_prozent)
|
||||
akku = PVAkku(
|
||||
self.kapazitaet_wh,
|
||||
hours=1,
|
||||
start_soc_prozent=50,
|
||||
min_soc_prozent=self.min_soc_prozent,
|
||||
max_soc_prozent=self.max_soc_prozent,
|
||||
)
|
||||
akku.reset()
|
||||
# Try to discharge more energy than available above min_soc
|
||||
abgegeben_wh, verlust_wh = akku.energie_abgeben(5000, 0) # Try to discharge 5000 Wh
|
||||
abgegeben_wh, verlust_wh = akku.energie_abgeben(
|
||||
5000, 0
|
||||
) # Try to discharge 5000 Wh
|
||||
expected_soc = self.min_soc_prozent # SoC should not drop below min_soc
|
||||
self.assertEqual(akku.ladezustand_in_prozent(), expected_soc, "SoC should not drop below min_soc after discharge")
|
||||
self.assertEqual(abgegeben_wh, 2640.0, "The energy discharged should be limited by min_soc")
|
||||
self.assertEqual(
|
||||
akku.ladezustand_in_prozent(),
|
||||
expected_soc,
|
||||
"SoC should not drop below min_soc after discharge",
|
||||
)
|
||||
self.assertEqual(
|
||||
abgegeben_wh, 2640.0, "The energy discharged should be limited by min_soc"
|
||||
)
|
||||
|
||||
def test_charge_above_max_soc(self):
|
||||
akku = PVAkku(self.kapazitaet_wh, hours=1, start_soc_prozent=50, min_soc_prozent=self.min_soc_prozent, max_soc_prozent=self.max_soc_prozent)
|
||||
akku = PVAkku(
|
||||
self.kapazitaet_wh,
|
||||
hours=1,
|
||||
start_soc_prozent=50,
|
||||
min_soc_prozent=self.min_soc_prozent,
|
||||
max_soc_prozent=self.max_soc_prozent,
|
||||
)
|
||||
akku.reset()
|
||||
# Try to charge more energy than available up to max_soc
|
||||
geladen_wh, verlust_wh = akku.energie_laden(5000, 0) # Try to charge 5000 Wh
|
||||
expected_soc = self.max_soc_prozent # SoC should not exceed max_soc
|
||||
self.assertEqual(akku.ladezustand_in_prozent(), expected_soc, "SoC should not exceed max_soc after charge")
|
||||
self.assertEqual(geladen_wh, 3000.0, "The energy charged should be limited by max_soc")
|
||||
self.assertEqual(
|
||||
akku.ladezustand_in_prozent(),
|
||||
expected_soc,
|
||||
"SoC should not exceed max_soc after charge",
|
||||
)
|
||||
self.assertEqual(
|
||||
geladen_wh, 3000.0, "The energy charged should be limited by max_soc"
|
||||
)
|
||||
|
||||
def test_charging_at_max_soc(self):
|
||||
akku = PVAkku(self.kapazitaet_wh, hours=1, start_soc_prozent=80, min_soc_prozent=self.min_soc_prozent, max_soc_prozent=self.max_soc_prozent)
|
||||
akku = PVAkku(
|
||||
self.kapazitaet_wh,
|
||||
hours=1,
|
||||
start_soc_prozent=80,
|
||||
min_soc_prozent=self.min_soc_prozent,
|
||||
max_soc_prozent=self.max_soc_prozent,
|
||||
)
|
||||
akku.reset()
|
||||
# Try to charge when SoC is already at max_soc
|
||||
geladen_wh, verlust_wh = akku.energie_laden(5000, 0)
|
||||
self.assertEqual(geladen_wh, 0.0, "No energy should be charged when at max_soc")
|
||||
self.assertEqual(akku.ladezustand_in_prozent(), self.max_soc_prozent, "SoC should remain at max_soc")
|
||||
self.assertEqual(
|
||||
akku.ladezustand_in_prozent(),
|
||||
self.max_soc_prozent,
|
||||
"SoC should remain at max_soc",
|
||||
)
|
||||
|
||||
def test_discharging_at_min_soc(self):
|
||||
akku = PVAkku(self.kapazitaet_wh, hours=1, start_soc_prozent=20, min_soc_prozent=self.min_soc_prozent, max_soc_prozent=self.max_soc_prozent)
|
||||
akku = PVAkku(
|
||||
self.kapazitaet_wh,
|
||||
hours=1,
|
||||
start_soc_prozent=20,
|
||||
min_soc_prozent=self.min_soc_prozent,
|
||||
max_soc_prozent=self.max_soc_prozent,
|
||||
)
|
||||
akku.reset()
|
||||
# Try to discharge when SoC is already at min_soc
|
||||
abgegeben_wh, verlust_wh = akku.energie_abgeben(5000, 0)
|
||||
self.assertEqual(abgegeben_wh, 0.0, "No energy should be discharged when at min_soc")
|
||||
self.assertEqual(akku.ladezustand_in_prozent(), self.min_soc_prozent, "SoC should remain at min_soc")
|
||||
self.assertEqual(
|
||||
abgegeben_wh, 0.0, "No energy should be discharged when at min_soc"
|
||||
)
|
||||
self.assertEqual(
|
||||
akku.ladezustand_in_prozent(),
|
||||
self.min_soc_prozent,
|
||||
"SoC should remain at min_soc",
|
||||
)
|
||||
|
||||
def test_soc_limits(self):
|
||||
# Test to ensure that SoC never exceeds max_soc or drops below min_soc
|
||||
akku = PVAkku(self.kapazitaet_wh, hours=1, start_soc_prozent=50, min_soc_prozent=self.min_soc_prozent, max_soc_prozent=self.max_soc_prozent)
|
||||
akku = PVAkku(
|
||||
self.kapazitaet_wh,
|
||||
hours=1,
|
||||
start_soc_prozent=50,
|
||||
min_soc_prozent=self.min_soc_prozent,
|
||||
max_soc_prozent=self.max_soc_prozent,
|
||||
)
|
||||
akku.reset()
|
||||
akku.soc_wh = (self.max_soc_prozent / 100) * self.kapazitaet_wh + 1000 # Manually set SoC above max limit
|
||||
akku.soc_wh = (
|
||||
self.max_soc_prozent / 100
|
||||
) * self.kapazitaet_wh + 1000 # Manually set SoC above max limit
|
||||
akku.soc_wh = min(akku.soc_wh, akku.max_soc_wh)
|
||||
self.assertLessEqual(akku.ladezustand_in_prozent(), self.max_soc_prozent, "SoC should not exceed max_soc")
|
||||
|
||||
akku.soc_wh = (self.min_soc_prozent / 100) * self.kapazitaet_wh - 1000 # Manually set SoC below min limit
|
||||
akku.soc_wh = max(akku.soc_wh, akku.min_soc_wh)
|
||||
self.assertGreaterEqual(akku.ladezustand_in_prozent(), self.min_soc_prozent, "SoC should not drop below min_soc")
|
||||
self.assertLessEqual(
|
||||
akku.ladezustand_in_prozent(),
|
||||
self.max_soc_prozent,
|
||||
"SoC should not exceed max_soc",
|
||||
)
|
||||
|
||||
if __name__ == '__main__':
|
||||
akku.soc_wh = (
|
||||
self.min_soc_prozent / 100
|
||||
) * self.kapazitaet_wh - 1000 # Manually set SoC below min limit
|
||||
akku.soc_wh = max(akku.soc_wh, akku.min_soc_wh)
|
||||
self.assertGreaterEqual(
|
||||
akku.ladezustand_in_prozent(),
|
||||
self.min_soc_prozent,
|
||||
"SoC should not drop below min_soc",
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
@@ -1,13 +1,14 @@
|
||||
import pytest
|
||||
|
||||
from modules.class_heatpump import Heatpump
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
@pytest.fixture(scope="function")
|
||||
def heatpump() -> Heatpump:
|
||||
""" Heatpump with 5 kw heating power and 24 h prediction
|
||||
"""
|
||||
"""Heatpump with 5 kw heating power and 24 h prediction"""
|
||||
return Heatpump(5000, 24)
|
||||
|
||||
|
||||
class TestHeatpump:
|
||||
def test_cop(self, heatpump):
|
||||
"""Testing calculate COP for variouse outside temperatures"""
|
||||
|
Reference in New Issue
Block a user