forked from duartegroup/autodE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_constraints.py
52 lines (34 loc) · 1.32 KB
/
test_constraints.py
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
import pytest
from autode.constraints import Constraints
def test_base_properties():
consts = Constraints()
assert 'constraints' in str(consts).lower()
assert 'constraints' in repr(consts).lower()
assert not consts.any
assert consts.distance is None
assert consts.cartesian is None
consts.update(distance={(0, 1): 1.0})
assert consts.any
assert consts.distance is not None and type(consts.distance) is dict
assert consts.cartesian is None
conts2 = Constraints(cartesian=[0], distance={(0, 1): 1.1})
assert conts2.cartesian is not None and conts2.distance is not None
assert '0' in str(conts2) and '1.1' in str(conts2)
def test_multiple_update():
consts = Constraints()
consts.update(distance={(0, 1): 1.0})
consts.update(distance={(1, 0): 1.0})
assert len(consts.distance) == 1
# Non unique pairs should be skipped
consts.update(distance={(0, 0): 1.0})
assert len(consts.distance) == 1
# Cannot have negative distances
with pytest.raises(ValueError):
consts.update(distance={(0, 1): -1.0})
def test_cartesian_update():
conts = Constraints(cartesian=[0, 1])
assert conts.any
assert len(conts.cartesian) == 2
# Should only have the unique components
conts.update(cartesian=[0])
assert len(conts.cartesian) == 2