Skip to content

Commit

Permalink
Implemented tests + changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
wouterpeere committed Nov 10, 2023
1 parent 50d302a commit 66efff3
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 2 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ All notable changes to this project will be documented in this file. For future

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [2.2.1] - 2024

## Added
- Equal functions for HourlyGeothermalLoad and MonthlyGeothermalLoadAbsolute (issue #189).

## fixed
- Bug in load-duration curve when not working with optimize load profile (issue # 189).


## [2.2.0] - 2023-10-17

## Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ def load_hourly_profile(self, file_path: str, header: bool = True, separator: st

ghe_logger.info("Hourly profile loaded!")

def __eq__(self, other):
def __eq__(self, other) -> bool:
if not isinstance(other, HourlyGeothermalLoad):
return False
if not np.array_equal(self.hourly_cooling_load, other.hourly_cooling_load):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,3 +328,18 @@ def set_peak_heating(self, load: Union[np.ndarray, list, tuple]) -> None:
values
"""
self.peak_heating = np.array(load)

def __eq__(self, other) -> bool:
if not isinstance(other, MonthlyGeothermalLoadAbsolute):
return False
if not np.array_equal(self.baseload_heating, other.baseload_heating):
return False
if not np.array_equal(self.baseload_cooling, other.baseload_cooling):
return False
if not np.array_equal(self.peak_heating, other.peak_heating):
return False
if not np.array_equal(self.peak_cooling, other.peak_cooling):
return False
if not self.simulation_period == other.simulation_period:
return False
return True
28 changes: 27 additions & 1 deletion GHEtool/test/unit-tests/test_hourly_load_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as np

from GHEtool import FOLDER
from GHEtool.VariableClasses import HourlyGeothermalLoad, HourlyGeothermalLoadMultiYear
from GHEtool.VariableClasses import HourlyGeothermalLoad, HourlyGeothermalLoadMultiYear, MonthlyGeothermalLoadAbsolute


def test_load_hourly_data():
Expand Down Expand Up @@ -181,3 +181,29 @@ def test_dhw():
assert np.array_equal(np.full(8760, 10), load.hourly_heating_load)
assert np.array_equal(np.full(12, 8760*10/12), load.baseload_heating)
assert load.imbalance == -8760*10


def test_eq():
profile_1 = HourlyGeothermalLoad()
profile_2 = MonthlyGeothermalLoadAbsolute()
assert not profile_1 == profile_2
assert profile_1 == profile_1

profile_2 = HourlyGeothermalLoad()
assert profile_1 == profile_2

profile_1.simulation_period = 55
assert profile_1 != profile_2

profile_1.hourly_cooling_load = np.linspace(0, 10000, 8760)
profile_2.simulation_period = 55
assert profile_1 != profile_2

profile_2.hourly_cooling_load = np.linspace(0, 10000, 8760)
assert profile_1 == profile_2

profile_1.hourly_heating_load = np.linspace(0, 8759, 8760)
assert profile_1 != profile_2

profile_2.hourly_heating_load = np.linspace(0, 8759, 8760)
assert profile_1 == profile_2
41 changes: 41 additions & 0 deletions GHEtool/test/unit-tests/test_monthly_load_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,44 @@ def test_yearly_heating_cooling():
load = MonthlyGeothermalLoadAbsolute(*load_case(2))
assert load.yearly_heating_load == 160000
assert load.yearly_cooling_load == 240000


def test_eq():
load_1 = MonthlyGeothermalLoadAbsolute(*load_case(2))
load_2 = MonthlyGeothermalLoadAbsolute(*load_case(2))

assert load_1 == load_2
load_2.simulation_period = 55
assert load_1 != load_2

load_1.simulation_period = 55
assert load_1 == load_2
load_1.baseload_cooling = [i + 1 for i in load_1.baseload_cooling]

assert load_1 != load_2
load_2.baseload_cooling = [i + 1 for i in load_2.baseload_cooling]
assert load_1 == load_2

load_1.simulation_period = 55
assert load_1 == load_2
load_1.baseload_heating = [i + 1 for i in load_1.baseload_heating]

assert load_1 != load_2
load_2.baseload_heating = [i + 1 for i in load_2.baseload_heating]
assert load_1 == load_2

load_1.simulation_period = 55
assert load_1 == load_2
load_1.peak_heating = [i + 1 for i in load_1.peak_heating]

assert load_1 != load_2
load_2.peak_heating = [i + 1 for i in load_2.peak_heating]
assert load_1 == load_2

load_1.simulation_period = 55
assert load_1 == load_2
load_1.peak_cooling = [i + 1 for i in load_1.peak_cooling]

assert load_1 != load_2
load_2.peak_cooling = [i + 1 for i in load_2.peak_cooling]
assert load_1 == load_2

0 comments on commit 66efff3

Please sign in to comment.