Skip to content

Commit

Permalink
EC-54 Test and implement check_heatnetwork_present
Browse files Browse the repository at this point in the history
This commit implements the check_heatnetwork_present method as part of
the notional FHS wrapper. It also creates a unit test covering this
method using the test input file. Note, that this test did not exist in
the python codebase, however it has helped to provide confidence in the
Rust port/implementation.
  • Loading branch information
kpinakula committed Oct 16, 2024
1 parent 19ff92d commit 3fa7415
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3535,6 +3535,10 @@ impl InputForProcessing {
.noise_nuisance
.unwrap_or(false)
}

pub(crate) fn heat_source_wet(&self) -> Option<&IndexMap<String, HeatSourceWetDetails>> {
self.input.heat_source_wet.as_ref()
}
}

#[cfg(test)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,41 @@
use itertools::Itertools;

use crate::{
compare_floats::max_of_2,
core::units::{LITRES_PER_CUBIC_METRE, SECONDS_PER_HOUR},
input::InputForProcessing,
input::{
HeatPumpSourceType,
HeatSourceWetDetails::{HeatPump, Hiu},
InputForProcessing,
},
};

fn check_heatnetwork_present(input: &InputForProcessing) -> bool {
let mut is_heat_network = false;

let heat_source_wet = input.heat_source_wet();

if heat_source_wet.is_some() {
let sources = heat_source_wet
.unwrap()
.iter()
.map(|(_, source)| source)
.collect_vec();

for source in sources {
match source {
Hiu { .. } => is_heat_network = true,
HeatPump {
source_type: HeatPumpSourceType::HeatNetwork,
..
} => is_heat_network = true,
_ => {}
};
}
}
is_heat_network
}

/// Calculate effective air change rate accoring to according to Part F 1.24 a
pub fn minimum_air_change_rate(
_input: &InputForProcessing,
Expand All @@ -29,3 +61,26 @@ pub fn minimum_air_change_rate(
* SECONDS_PER_HOUR as f64
/ LITRES_PER_CUBIC_METRE as f64
}

#[cfg(test)]
mod tests {
use super::*;
use rstest::{fixture, rstest};
use std::fs::File;
use std::io::BufReader;
use std::path::Path;

#[fixture]
fn test_input() -> InputForProcessing {
let reader = BufReader::new(File::open(Path::new("src/wrappers/future_homes_standard/test_future_homes_standard_notional_input_data.json")).unwrap());
InputForProcessing::init_with_json(reader).expect(
"expected valid test_future_homes_standard_notional_input_data.json to be present",
)
}

#[rstest]
/// test written in Rust, not present in Python
fn test_check_heatnetwork_present(test_input: InputForProcessing) {
assert_eq!(check_heatnetwork_present(&test_input), false);
}
}

0 comments on commit 3fa7415

Please sign in to comment.