"""Test functions for utility_functions module.""" from typing import Dict import numpy as np import pytest import mvcm.utility_functions as utils @pytest.fixture def spatial_var_test_arr(): """Define reference input array for spatial_var() function test.""" arr = np.array( [ [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [5, 5, 5, 5, 5, 5, 5, 5, 5, 5], [1, 1, 1, 1, 8, 8, 8, 1, 1, 1], [5, 5, 5, 5, 7, 9, 8, 5, 5, 5], [1, 1, 1, 1, 8, 8, 7, 1, 1, 1], [5, 5, 5, 5, 5, 5, 5, 5, 5, 5], [9, 8, 7, 1, 1, 1, 1, 1, 1, 1], [7, 8, 8, 5, 5, 5, 5, 5, 5, 5], [8, 9, 8, 1, 1, 1, 1, 1, 1, 1], [5, 5, 5, 5, 5, 5, 5, 5, 5, 5], ], dtype=float, ) return arr @pytest.fixture def ref_spatial_var(): """Define reference output array for spatial_var() function test.""" arr = np.array( [ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], ], dtype=float, ) return arr @pytest.fixture def thresholds(): """Define thresholds for spatial_var() function test.""" return {"thr": 2} def test_spatial_var( spatial_var_test_arr: np.ndarray, thresholds: Dict, ref_spatial_var: np.ndarray ) -> None: """Test spatial_var function.""" var = utils.spatial_var(spatial_var_test_arr, thresholds["thr"]) assert np.allclose(np.floor(var), ref_spatial_var)