Skip to content

Commit 33dfaae

Browse files
committed
add test for misc, thanks gpt
1 parent b831e73 commit 33dfaae

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

tests/util/test_misc.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
from __future__ import annotations
2+
3+
import numpy as np
4+
5+
from pymatgen.util.misc import is_np_dict_equal
6+
7+
8+
class TestIsNpDictEqual:
9+
def test_different_keys(self):
10+
"""Test two dicts with different keys."""
11+
dict1 = {"a": np.array([1, 2, 3])}
12+
dict2 = {"a": np.array([1, 2, 3]), "b": "hello"}
13+
assert not is_np_dict_equal(dict1, dict2)
14+
15+
def test_both_list(self):
16+
"""Test two dicts where both have lists as values."""
17+
dict1 = {"a": [1, 2, 3]}
18+
dict2 = {"a": [1, 2, 3]}
19+
assert is_np_dict_equal(dict1, dict2)
20+
21+
def test_both_np_array(self):
22+
"""Test two dicts where both have NumPy arrays as values."""
23+
dict1 = {"a": np.array([1, 2, 3])}
24+
dict2 = {"a": np.array([1, 2, 3])}
25+
assert is_np_dict_equal(dict1, dict2)
26+
27+
def test_one_np_one_list(self):
28+
"""Test two dicts where one has a NumPy array and the other has a list."""
29+
dict1 = {"a": np.array([1, 2, 3])}
30+
dict2 = {"a": [1, 2, 3]}
31+
assert is_np_dict_equal(dict1, dict2)
32+
33+
def test_nested_arrays(self):
34+
"""Test two dicts with deeper nested arrays."""
35+
dict1 = {"a": np.array([[1, 2], [3, 4]])}
36+
dict2 = {"a": np.array([[1, 2], [3, 4]])}
37+
assert is_np_dict_equal(dict1, dict2)
38+
39+
dict3 = {"a": np.array([[1, 2], [3, 5]])}
40+
assert not is_np_dict_equal(dict1, dict3)

0 commit comments

Comments
 (0)