Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"""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)