-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_utils.py
94 lines (74 loc) · 3.02 KB
/
test_utils.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
from autodeer.utils import *
def test_gcd():
assert gcd([2.0, 4.0, 6.0, 8.0]) == 2
assert gcd([1.5, 3.0]) == 1.5
assert gcd([3, 6, 9, 12]) == 3
assert gcd([5, 10, 15, 20]) == 5
assert gcd([7, 14, 21, 28]) == 7
assert gcd([8, 12, 16, 20]) == 4
assert gcd([10, 20, 30, 40]) == 10
assert gcd([15, 25, 35, 45]) == 5
assert gcd([18, 24, 30, 36]) == 6
assert gcd([21, 28, 35, 42]) == 7
assert gcd([27, 36, 45, 54]) == 9
def test_transpose_dict_of_list():
d = {'a': [1, 2, 3], 'b': [4, 5, 6], 'c': [7, 8, 9]}
expected = [{'a': 1, 'b': 4, 'c': 7}, {'a': 2, 'b': 5, 'c': 8}, {'a': 3, 'b': 6, 'c': 9}]
assert transpose_dict_of_list(d) == expected
d = {'a': [1, 2], 'b': [3, 4], 'c': [5, 6]}
expected = [{'a': 1, 'b': 3, 'c': 5}, {'a': 2, 'b': 4, 'c': 6}]
assert transpose_dict_of_list(d) == expected
d = {'a': [1], 'b': [2], 'c': [3]}
expected = [{'a': 1, 'b': 2, 'c': 3}]
assert transpose_dict_of_list(d) == expected
d = {'a': [], 'b': [], 'c': []}
expected = []
assert transpose_dict_of_list(d) == expected
def test_transpose_list_of_dicts():
d = [{'a': 1, 'b': 4, 'c': 7}, {'a': 2, 'b': 5, 'c': 8}, {'a': 3, 'b': 6, 'c': 9}]
expected = {'a': [1, 2, 3], 'b': [4, 5, 6], 'c': [7, 8, 9]}
assert transpose_list_of_dicts(d) == expected
d = [{'a': 1, 'b': 3, 'c': 5}, {'a': 2, 'b': 4, 'c': 6}]
expected = {'a': [1, 2], 'b': [3, 4], 'c': [5, 6]}
assert transpose_list_of_dicts(d) == expected
d = [{'a': 1, 'b': 2, 'c': 3}]
expected = {'a': [1], 'b': [2], 'c': [3]}
assert transpose_list_of_dicts(d) == expected
d = []
expected = {}
assert transpose_list_of_dicts(d) == expected
import numpy as np
from autodeer import Parameter
import pytest
def test_val_in_ns():
# Test with no axis
p = Parameter(name='p', value=10, unit="ns")
assert val_in_ns(p) == 10
p = Parameter(name='p', value=10, unit="us")
assert val_in_ns(p) == 10000
# Test with one axis
p = Parameter(name='p', value=10, unit="ns", step=5, dim=1)
assert np.all(val_in_ns(p) == np.array([10]))
p = Parameter(name='p', value=10, unit="ns", step=5, dim=3)
assert np.all(val_in_ns(p) == np.array([10,15,20]))
# Test with two axis
p = Parameter(name='p', value=10, unit="ns", step=5, dim=2)
p.add_axis(2,axis=np.array([1,2]))
with pytest.raises(ValueError):
val_in_ns(p)
def test_val_in_us():
# Test with no axis
p = Parameter(name='p', value=10, unit="ns")
assert val_in_us(p) == 0.01
p = Parameter(name='p', value=10, unit="us")
assert val_in_us(p) == 10
# Test with one axis
p = Parameter(name='p', value=10, unit="us", step=5, dim=1)
assert np.all(val_in_us(p) == np.array([10]))
p = Parameter(name='p', value=10, unit="us", step=5, dim=3)
assert np.all(val_in_us(p) == np.array([10,15,20]))
# Test with two axis
p = Parameter(name='p', value=10, unit="us", step=5, dim=2)
p.add_axis(2,axis=np.array([1,2]))
with pytest.raises(ValueError):
val_in_us(p)