-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_coordinates.py
78 lines (50 loc) · 1.97 KB
/
test_coordinates.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
from simulatedmicroscopy import Coordinates
import numpy as np
import pytest
def demo_coordinates():
return np.array(
[
[0.0, 0.0, 0.0],
[1.0, 0.0, 0.0],
[0.0, 1.0, 0.0],
[0.0, 0.0, 1.0],
]
)
def test_coordinates():
coordinates = demo_coordinates()
cs = Coordinates(coordinates)
assert (cs.coordinates == coordinates).all()
def test_coordinates_2D():
coordinates = np.array([[1.0, 0.0], [0.0, 1.0], [2, 0.0], [0.0, 2.0]])
cs = Coordinates(coordinates)
assert (cs.coordinates == coordinates).all()
def test_coordinates_wrongshape():
# instead of given an (N,3) array, give (3,N) array
coordinates = demo_coordinates().T
# should atomatically transpose but also give a warning
with pytest.warns(Warning):
cs = Coordinates(coordinates)
assert cs.coordinates.shape[0] == coordinates.shape[1]
def test_coordinates_wrongshape_1d():
# instead of given an (N,3) array, give 1d array)
coordinates = demo_coordinates().flat
# should raise ValueError
with pytest.raises(ValueError):
Coordinates(coordinates)
def test_coordinates_wrongshape_5x5():
# instead of given an (N,3) array, give 5x5 array)
coordinates = np.zeros(shape=(5, 5))
# should raise ValueError
with pytest.raises(ValueError):
Coordinates(coordinates)
@pytest.mark.parametrize("scaling_factor", [0.3, 1.0, 1.5, 2.0])
def test_scaling(scaling_factor):
cs = Coordinates(demo_coordinates())
scaled_coords = cs.scale(scaling_factor)
assert (cs.coordinates == scaled_coords).all()
assert (cs.coordinates == demo_coordinates() * scaling_factor).all()
@pytest.mark.parametrize("unit,scaling_factor", [("nm", 1e3), ("µm", 1.0)])
def test_get_coordinates_unit(unit, scaling_factor):
cs = Coordinates(demo_coordinates())
converted_coords = cs.get_coordinates(unit=unit)
assert (converted_coords == demo_coordinates() * scaling_factor).all()