From aaa501d44bb7a63d0d3cfe85d2dd7532a8f4c6db Mon Sep 17 00:00:00 2001 From: Dominic Orchard Date: Mon, 18 Nov 2024 23:25:37 +0000 Subject: [PATCH 1/4] idea of testing set-get behaviour --- src/bmi_tester/_tests/stage_2/var_test.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/bmi_tester/_tests/stage_2/var_test.py b/src/bmi_tester/_tests/stage_2/var_test.py index c47d667..c51291c 100644 --- a/src/bmi_tester/_tests/stage_2/var_test.py +++ b/src/bmi_tester/_tests/stage_2/var_test.py @@ -59,3 +59,26 @@ def test_get_var_units(initialized_bmi, var_name): units = initialized_bmi.get_var_units(var_name) assert isinstance(units, str) assert check_unit_is_valid(units) + +def test_put_get(initialized_bmi): + """Test fundmanetal state behaviour of every output variable which is also an input variable:""" + + # Take the intersection of output and input vars + for var_name in initialized_bmi.get_output_var_names(): + if var_name in initialized_bmi.get_input_var_names(): + + # Get the variables type + ty = np.dtype(initialized_bmi.get_var_type(var_name)) + # Generate some systematic base cases for this type + zero = np.zeros(1, dtype=ty) + one = np.ones(1, dtype=ty) + for val in [zero, one, one + one]: + # Test set-get behaviour + # (i.e., setting a value then getting it produces the same result) + initialized_bmi.set_value(var_name, val) + assert initialized_bmi.get_value(var_name) == val + + # Test set-set-get behaviour + # (i.e., setting is idempotent; setting twice has no visible effect) + initialized_bmi.set_value(var_name, val) + assert initialized_bmi.get_value(var_name) == val \ No newline at end of file From 693bcb56086a3b3e4806fbf39adde956e4b8fb7c Mon Sep 17 00:00:00 2001 From: Dominic Orchard Date: Mon, 18 Nov 2024 23:30:36 +0000 Subject: [PATCH 2/4] capture the intermediate value of the first get --- src/bmi_tester/_tests/stage_2/var_test.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/bmi_tester/_tests/stage_2/var_test.py b/src/bmi_tester/_tests/stage_2/var_test.py index c51291c..f3f34a0 100644 --- a/src/bmi_tester/_tests/stage_2/var_test.py +++ b/src/bmi_tester/_tests/stage_2/var_test.py @@ -76,9 +76,11 @@ def test_put_get(initialized_bmi): # Test set-get behaviour # (i.e., setting a value then getting it produces the same result) initialized_bmi.set_value(var_name, val) - assert initialized_bmi.get_value(var_name) == val + val_out = initialized_bmi.get_value(var_name) + assert val_out == val # Test set-set-get behaviour # (i.e., setting is idempotent; setting twice has no visible effect) initialized_bmi.set_value(var_name, val) - assert initialized_bmi.get_value(var_name) == val \ No newline at end of file + val_out_again = initialized_bmi.get_value(var_name) + assert val_out_again == val_out \ No newline at end of file From 7dbf2cd2623a24ff891bbd8ed9578572f0a3e40e Mon Sep 17 00:00:00 2001 From: Dominic Orchard Date: Mon, 18 Nov 2024 23:34:14 +0000 Subject: [PATCH 3/4] tweak comment --- src/bmi_tester/_tests/stage_2/var_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bmi_tester/_tests/stage_2/var_test.py b/src/bmi_tester/_tests/stage_2/var_test.py index f3f34a0..540c2f1 100644 --- a/src/bmi_tester/_tests/stage_2/var_test.py +++ b/src/bmi_tester/_tests/stage_2/var_test.py @@ -69,7 +69,7 @@ def test_put_get(initialized_bmi): # Get the variables type ty = np.dtype(initialized_bmi.get_var_type(var_name)) - # Generate some systematic base cases for this type + # Generate some systematic test cases for this variable's type zero = np.zeros(1, dtype=ty) one = np.ones(1, dtype=ty) for val in [zero, one, one + one]: From c031bf8eed9799c9443a4b6fd53e76e742e9e4d3 Mon Sep 17 00:00:00 2001 From: Dominic Orchard Date: Mon, 18 Nov 2024 23:35:03 +0000 Subject: [PATCH 4/4] change test name --- src/bmi_tester/_tests/stage_2/var_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bmi_tester/_tests/stage_2/var_test.py b/src/bmi_tester/_tests/stage_2/var_test.py index 540c2f1..dc85dc9 100644 --- a/src/bmi_tester/_tests/stage_2/var_test.py +++ b/src/bmi_tester/_tests/stage_2/var_test.py @@ -60,7 +60,7 @@ def test_get_var_units(initialized_bmi, var_name): assert isinstance(units, str) assert check_unit_is_valid(units) -def test_put_get(initialized_bmi): +def test_set_get_interaction(initialized_bmi): """Test fundmanetal state behaviour of every output variable which is also an input variable:""" # Take the intersection of output and input vars