From a8dfbffe9663d20170c519eca5b339a63ff29eff Mon Sep 17 00:00:00 2001 From: softwareengineerprogrammer <4056124+softwareengineerprogrammer@users.noreply.github.com> Date: Tue, 30 Apr 2024 09:44:54 -0700 Subject: [PATCH] Unit test re: https://github.com/NREL/GEOPHIRES-X/issues/192 --- .../MC_GEOPHIRES_Settings_file-3.txt | 4 +++ .../test_geophires_monte_carlo.py | 29 +++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 tests/geophires_monte_carlo_tests/MC_GEOPHIRES_Settings_file-3.txt diff --git a/tests/geophires_monte_carlo_tests/MC_GEOPHIRES_Settings_file-3.txt b/tests/geophires_monte_carlo_tests/MC_GEOPHIRES_Settings_file-3.txt new file mode 100644 index 00000000..e4ce8300 --- /dev/null +++ b/tests/geophires_monte_carlo_tests/MC_GEOPHIRES_Settings_file-3.txt @@ -0,0 +1,4 @@ +INPUT, Gradient 1, triangular, 36, 41, 44 +OUTPUT, Average Net Electricity Production +OUTPUT, Electricity breakeven price +ITERATIONS, 3 diff --git a/tests/geophires_monte_carlo_tests/test_geophires_monte_carlo.py b/tests/geophires_monte_carlo_tests/test_geophires_monte_carlo.py index f7a2fefd..22a6f217 100644 --- a/tests/geophires_monte_carlo_tests/test_geophires_monte_carlo.py +++ b/tests/geophires_monte_carlo_tests/test_geophires_monte_carlo.py @@ -1,5 +1,6 @@ import json import os +import re import unittest from pathlib import Path @@ -107,6 +108,34 @@ def test_monte_carlo_result_ordering(self): self.assertDictEqual(result_json_obj, result.result['output']) + def test_geophires_monte_carlo_single_input(self): + """https://github.com/NREL/GEOPHIRES-X/issues/192""" + + client = GeophiresMonteCarloClient() + num_iterations = 3 + + input_file_path: Path = self._get_arg_file_path('GEOPHIRES-example1.txt') + mc_settings_file_path: Path = self._get_arg_file_path('MC_GEOPHIRES_Settings_file-3.txt') + result: MonteCarloResult = client.get_monte_carlo_result( + MonteCarloRequest( + SimulationProgram.GEOPHIRES, + input_file_path, + mc_settings_file_path, + ) + ) + self.assertIsNotNone(result) + self.assertIsNotNone(result.output_file_path) + + with open(result.output_file_path) as f: + result_content = f.read() + self.assertIn( + 'Average Net Electricity Production, Electricity breakeven price, Gradient 1', + result_content, + ) + gradient_inputs = re.compile(r'\(Gradient\s1\:[3-4][0-9]\.[0-9]+').findall(result_content) + self.assertEqual(num_iterations, len(gradient_inputs)) + self.assertEqual(num_iterations, len(set(gradient_inputs))) # verify unique values were generated + def test_hip_ra_monte_carlo(self): client = GeophiresMonteCarloClient()