-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
401: tests for mode_2d_arearat mode_3d_ratio ctc (#421)
* 401: tests for mode_2d_arearat mode_3d_ratio ctc * 401: refactor to fix sonarqube issues
- Loading branch information
1 parent
210fb30
commit 11b337d
Showing
6 changed files
with
228 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import pytest | ||
from unittest.mock import patch | ||
import numpy as np | ||
import metcalcpy.util.mode_2d_arearat_statistics as m2as | ||
from test.utils import MODE_TEST_DATA as data | ||
|
||
column_names = np.array( | ||
["object_type", "area", "fcst_flag", "simple_flag", "matched_flag"] | ||
) | ||
|
||
data = np.array( | ||
[ | ||
["2d", 100, 1, 1, 1], | ||
["2d", 30, 0, 1, 1], | ||
["2d", 120, 1, 1, 0], | ||
["2d", 12, 0, 1, 1], | ||
["2d", 1, 1, 0, 1], | ||
["2d", 17, 0, 1, 1], | ||
["2d", 200, 1, 1, 1], | ||
["3d", 66, 0, 1, 0], | ||
] | ||
) | ||
|
||
@pytest.mark.parametrize( | ||
"func_name,data_values,expected", | ||
[ | ||
("arearat_fsa_asa", data, 0.8768267), | ||
("arearat_osa_asa", data, 0.1231733), | ||
("arearat_asm_asa", data, 0.7494781), | ||
("arearat_asu_asa", data, 0.2505219), | ||
("arearat_fsm_fsa", data, 0.7142857), | ||
("arearat_fsu_fsa", data, 0.2857143), | ||
("arearat_osm_osa", data, 1.0), | ||
("arearat_osu_osa", data, None), | ||
("arearat_fsm_asm", data, 0.2857143), | ||
("arearat_osm_asm", data, 0.1643454), | ||
("arearat_osu_asu", data, None), | ||
("arearat_fsa_aaa", data, 0.875), | ||
("arearat_osa_aaa", data, 0.1229167), | ||
("arearat_fsa_faa", data, 0.9976247), | ||
("arearat_fca_faa", data, 0.0023753), | ||
("arearat_osa_oaa", data, 1.0), | ||
("arearat_oca_oaa", data, None), | ||
("arearat_fca_aca", data, 1.0), | ||
("arearat_oca_aca", data, None), | ||
("arearat_fsa_osa", data, 7.1186441), | ||
("arearat_osa_fsa", data, 1.0), | ||
("arearat_aca_asa", data, 0.0020877), | ||
("arearat_asa_aca", data, 479.0), | ||
("arearat_fca_fsa", data, 0.002381), | ||
("arearat_fsa_fca", data, 420.0), | ||
("arearat_oca_osa", data, None), | ||
("arearat_osa_oca", data, None), | ||
("objahits", data, 179.5), | ||
("objamisses", data, None), | ||
("objafas", data, 120.0), | ||
("objacsi", data, 0.5993322), | ||
("objapody", data, None), | ||
("objafar", data, 0.1431981), | ||
], | ||
) | ||
def test_calculate_3d_ratio(func_name, data_values, expected): | ||
func_str = f"calculate_2d_{func_name}" | ||
func = getattr(m2as, func_str) | ||
actual = func(data_values, column_names) | ||
assert actual == expected | ||
|
||
# Check None is returned on Exception | ||
with patch.object(m2as, "column_data_by_name_value", side_effect=TypeError): | ||
actual = func(data_values, column_names) | ||
assert actual == None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import pytest | ||
from unittest.mock import patch | ||
import numpy as np | ||
import metcalcpy.util.mode_3d_ratio_statistics as m3rs | ||
|
||
column_names = np.array( | ||
["object_type", "volume", "fcst_flag", "simple_flag", "matched_flag"] | ||
) | ||
|
||
data = np.array( | ||
[ | ||
["3d", 100, 1, 1, 1], | ||
["3d", 30, 0, 1, 1], | ||
["3d", 120, 1, 1, 0], | ||
["3d", 12, 0, 1, 1], | ||
["3d", 1, 1, 0, 1], | ||
["3d", 17, 0, 1, 1], | ||
["2d", 200, 1, 1, 1], | ||
["3d", 66, 0, 1, 0], | ||
] | ||
) | ||
|
||
@pytest.mark.parametrize( | ||
"func_name,data_values,expected", | ||
[ | ||
("ratio_fsa_asa", data, 0.3333333), | ||
("ratio_osa_asa", data, 0.6666667), | ||
("ratio_asm_asa", data, 0.6666667), | ||
("ratio_asu_asa", data, 0.3333333), | ||
("ratio_fsm_fsa", data, 1.0), | ||
("ratio_fsu_fsa", data, 0.5), | ||
("ratio_osm_osa", data, 0.75), | ||
("ratio_osu_osa", data, 0.25), | ||
("ratio_fsm_asm", data, 0.25), | ||
("ratio_osm_asm", data, 0.25), | ||
("ratio_fsu_asu", data, 0.5), | ||
("ratio_osu_asu", data, 0.5), | ||
("ratio_fsa_aaa", data, 0.2857143), | ||
("ratio_osa_aaa", data, 0.5714286), | ||
("ratio_fsa_faa", data, 0.6666667), | ||
("ratio_fca_faa", data, 0.3333333), | ||
("ratio_osa_oaa", data, 1.0), | ||
("ratio_oca_oaa", data, 0.0), | ||
("ratio_fca_aca", data, 1.0), | ||
("ratio_fsa_osa", data, 0.5), | ||
("ratio_osa_fsa", data, 2.0), | ||
("ratio_asa_aca", data, 6.0), | ||
("ratio_fca_fsa", data, 0.5), | ||
("ratio_fsa_fca", data, 2.0), | ||
("ratio_oca_osa", data, 0.0), | ||
("ratio_osa_oca", data, None), | ||
("objhits", data, 2.0), | ||
("objmisses", data, 1.0), | ||
("objfas", data, 1.0), | ||
("objcsi", data, 0.5), | ||
("objpody", data, 0.6666667), | ||
("objfar", data, 0.3333333), | ||
], | ||
) | ||
def test_calculate_3d_ratio(func_name, data_values, expected): | ||
func_str = f"calculate_3d_{func_name}" | ||
func = getattr(m3rs, func_str) | ||
actual = func(data_values, column_names) | ||
assert actual == expected | ||
|
||
# Check None is returned on Exception | ||
with patch.object(m3rs, "column_data_by_name_value", side_effect=TypeError): | ||
actual = func(data_values, column_names) | ||
assert actual == None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,22 @@ | ||
from pathlib import Path | ||
import numpy as np | ||
|
||
def abs_path(rel_path): | ||
"""Turn a relative path into abs path""" | ||
return str(Path(str(Path(__file__).parents[2])) / rel_path) | ||
|
||
# Datafile access | ||
AGG_STAT_AND_BOOT_DATA = abs_path("METcalcpy/test/data/agg_stat_and_boot_data.data") | ||
AGG_STAT_AND_BOOT_DATA = abs_path("METcalcpy/test/data/agg_stat_and_boot_data.data") | ||
|
||
MODE_TEST_DATA = np.array( | ||
[ | ||
["3d", 100, 1, 1, 1], | ||
["3d", 30, 0, 1, 1], | ||
["3d", 120, 1, 1, 0], | ||
["3d", 12, 0, 1, 1], | ||
["3d", 1, 1, 0, 1], | ||
["3d", 17, 0, 1, 1], | ||
["2d", 200, 1, 1, 1], | ||
["3d", 66, 0, 1, 0], | ||
] | ||
) |