-
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.
- Loading branch information
1 parent
5983c27
commit cfb67a0
Showing
1 changed file
with
40 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
"""Tests for singlepoint calculation helper functions.""" | ||
|
||
from __future__ import annotations | ||
|
||
import numpy as np | ||
|
||
from api.utils.singlepoint_helper import convert_ndarray_to_list | ||
|
||
|
||
def test_convert_ndarray_to_list_with_array(): | ||
"""Test convert_ndarray_to_list function with a np array.""" | ||
array = np.array([1, 2, 3]) | ||
result = convert_ndarray_to_list(array) | ||
assert result == [1, 2, 3] | ||
|
||
|
||
def test_convert_ndarray_to_list_with_nested_dict(): | ||
"""Test convert_ndarray_to_list function with a nested dict.""" | ||
import numpy as np | ||
|
||
nested_dict = {"a": np.array([1, 2, 3]), "b": {"c": np.array([4, 5, 6])}} | ||
result = convert_ndarray_to_list(nested_dict) | ||
expected = {"a": [1, 2, 3], "b": {"c": [4, 5, 6]}} | ||
assert result == expected | ||
|
||
|
||
def test_convert_ndarray_to_list_with_list(): | ||
"""Test convert_ndarray_to_list function with list of np arrays.""" | ||
import numpy as np | ||
|
||
list_of_arrays = [np.array([1, 2]), np.array([3, 4])] | ||
result = convert_ndarray_to_list(list_of_arrays) | ||
assert result == [[1, 2], [3, 4]] | ||
|
||
|
||
def test_convert_ndarray_to_list_with_non_numpy(): | ||
"""Test convert_ndarray_to_list function with a float value.""" | ||
obj = -843.033131230741 | ||
result = convert_ndarray_to_list(obj) | ||
assert result == -843.033131230741 |