Skip to content

Commit

Permalink
Test if 100% coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
wouterpeere committed Feb 10, 2024
1 parent 2d63045 commit c520b25
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 3 deletions.
16 changes: 13 additions & 3 deletions GHEtool/test/unit-tests/test_hourly_load_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,19 @@ def test_monthly_based_on_hourly_multi_year():
assert np.allclose(load.baseload_heating_power_simulation_period, heating_bl/730)
assert np.allclose(load.baseload_cooling_power_simulation_period, heating_bl * 2/730)
assert np.allclose(load.monthly_average_load_simulation_period, heating_bl/730)
# TODO test for monthly multiyear
# TODO test for hour_series
# TODO test for reduce_to_monthly


def test_resample_to_monthly_multiyear():
load = HourlyGeothermalLoadMultiYear()
load.simulation_period = 2
peak, baseload = load.resample_to_monthly(np.tile(np.linspace(0, 729, 730), 24))
assert np.array_equal(peak, np.full(24, 729))
assert np.array_equal(baseload, np.full(24, 266085))
load.all_months_equal = False
peak, baseload = load.resample_to_monthly(np.tile(np.linspace(0, 729, 730), 24))
assert np.array_equal(peak, np.tile(np.array([729., 685., 729., 729., 729., 729., 729., 729., 729., 729., 729., 729.]), 2))
assert np.array_equal(baseload, np.tile(np.array([266176., 234864., 275780., 259140., 275836., 259100.,
275892., 276088., 258920., 276144., 258880., 276200.]), 2))


def test_dhw():
Expand Down
107 changes: 107 additions & 0 deletions GHEtool/test/unit-tests/test_monthly_load_multi_year.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import pytest

import numpy as np
from GHEtool import MonthlyGeothermalLoadMultiYear

# Initialize test data
baseload_heating = np.array([1000] * 12) # 1000 kWh/month for each month
baseload_cooling = np.array([500] * 12) # 500 kWh/month for each month
peak_heating = np.array([50] * 12) # 50 kW/month for each month
peak_cooling = np.array([30] * 12) # 30 kW/month for each month

# Initialize the MonthlyGeothermalLoadMultiYear object with test data
load_data = MonthlyGeothermalLoadMultiYear(
baseload_heating=baseload_heating,
baseload_cooling=baseload_cooling,
peak_heating=peak_heating,
peak_cooling=peak_cooling
)


def test_baseload_heating():
assert np.array_equal(load_data.baseload_heating, baseload_heating)


def test_baseload_cooling():
assert np.array_equal(load_data.baseload_cooling, baseload_cooling)


def test_peak_heating():
assert np.array_equal(load_data.peak_heating, peak_heating)


def test_peak_cooling():
assert np.array_equal(load_data.peak_cooling, peak_cooling)


def test_baseload_heating_simulation_period():
expected_output = np.array([1000] * 12) # Average heating load for the simulation period
assert np.array_equal(load_data.baseload_heating_simulation_period, expected_output)


def test_baseload_cooling_simulation_period():
expected_output = np.array([500] * 12) # Average cooling load for the simulation period
assert np.array_equal(load_data.baseload_cooling_simulation_period, expected_output)


def test_peak_heating_simulation_period():
expected_output = np.array([50] * 12) # Average peak heating load for the simulation period
assert np.array_equal(load_data.peak_heating_simulation_period, expected_output)


def test_peak_cooling_simulation_period():
expected_output = np.array([30] * 12) # Average peak cooling load for the simulation period
assert np.array_equal(load_data.peak_cooling_simulation_period, expected_output)


def test_baseload_heating_power_simulation_period():
expected_output = baseload_heating / load_data.UPM
assert np.array_equal(load_data.baseload_heating_power_simulation_period, expected_output)


def test_baseload_cooling_power_simulation_period():
expected_output = baseload_cooling / load_data.UPM
assert np.array_equal(load_data.baseload_cooling_power_simulation_period, expected_output)


def test_monthly_average_load_simulation_period():
expected_output = (baseload_cooling / load_data.UPM) - (baseload_heating / load_data.UPM)
assert np.array_equal(load_data.monthly_average_load_simulation_period, expected_output)


def test_baseload_heating_setter():
new_baseload_heating = np.array([800] * 12) # New baseload heating values
load_data.baseload_heating = new_baseload_heating
assert np.array_equal(load_data.baseload_heating, new_baseload_heating)


def test_baseload_cooling_setter():
new_baseload_cooling = np.array([400] * 12) # New baseload cooling values
load_data.baseload_cooling = new_baseload_cooling
assert np.array_equal(load_data.baseload_cooling, new_baseload_cooling)


def test_peak_heating_setter():
new_peak_heating = np.array([60] * 12) # New peak heating values
load_data.peak_heating = new_peak_heating
assert np.array_equal(load_data.peak_heating, new_peak_heating)


def test_peak_cooling_setter():
new_peak_cooling = np.array([35] * 12) # New peak cooling values
load_data.peak_cooling = new_peak_cooling
assert np.array_equal(load_data.peak_cooling, new_peak_cooling)


def test_input_validation():
# Test input validation for non-array input
with pytest.raises(ValueError):
load_data.baseload_heating = 1000

# Test input validation for negative values
with pytest.raises(ValueError):
load_data.peak_cooling = np.array([-30] * 12)

# Test input validation for incorrect length
with pytest.raises(ValueError):
load_data.peak_heating = np.array([40] * 15)

0 comments on commit c520b25

Please sign in to comment.