|
1
|
|
|
import numpy as np |
|
2
|
|
|
import pandas as pd |
|
3
|
|
|
|
|
4
|
|
|
|
|
5
|
|
|
import calculations |
|
6
|
|
|
|
|
7
|
|
|
|
|
8
|
|
|
def peak_detection(Dataframe_y): |
|
9
|
|
|
list = [0, 1] |
|
10
|
|
|
return list |
|
11
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
def split(vector): |
|
14
|
|
|
split = int(len(vector)/2) |
|
15
|
|
|
end = int(len(vector)) |
|
16
|
|
|
vector1 = np.array(vector)[0:split] |
|
17
|
|
|
vector2 = np.array(vector)[split:end] |
|
18
|
|
|
return vector1, vector2 |
|
19
|
|
|
|
|
20
|
|
|
|
|
21
|
|
|
def linear_background(x, y): |
|
22
|
|
|
fake_line_list = [1, 2, 3, 4] |
|
23
|
|
|
fake_line_array = np.array(fake_line_list) |
|
24
|
|
|
return fake_line_array |
|
25
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
def test_peak_values(): |
|
28
|
|
|
"""This function tests peak_values() function.""" |
|
29
|
|
|
potentials = [0.500, 0.499, 0.498, 0.497] |
|
30
|
|
|
currents = [7.040, 6.998, 8.256, 8.286] |
|
31
|
|
|
potentials_d = pd.DataFrame(potentials) |
|
32
|
|
|
currents_d = pd.DataFrame(currents) |
|
33
|
|
|
|
|
34
|
|
|
assert type(calculations.peak_values(potentials_d, currents_d)) == np.ndarray, "output is not an array" |
|
35
|
|
|
assert calculations.peak_values(potentials_d, currents_d)[0] == 0.498, "array value incorrect for data" |
|
36
|
|
|
assert calculations.peak_values(potentials_d, currents_d)[2] == 0.499, "array value incorrect for data" |
|
37
|
|
|
assert calculations.peak_values(potentials_d, currents_d)[1] == 8.256, "array value incorrect for data" |
|
38
|
|
|
assert calculations.peak_values(potentials_d, currents_d)[3] == 6.998, "array value incorrect for data" |
|
39
|
|
|
return |
|
40
|
|
|
|
|
41
|
|
|
|
|
42
|
|
|
def test_del_potential(): |
|
43
|
|
|
"""This function tests the del_potential function.""" |
|
44
|
|
|
potentials = [0.500, 0.498, 0.499, 0.497] |
|
45
|
|
|
currents = [7.040, 6.998, 8.256, 8.286] |
|
46
|
|
|
potentials_d = pd.DataFrame(potentials) |
|
47
|
|
|
currents_d = pd.DataFrame(currents) |
|
48
|
|
|
|
|
49
|
|
|
assert type(calculations.del_potential(potentials_d, currents_d)) == np.ndarray, "output is not an array" |
|
50
|
|
|
assert calculations.del_potential(potentials_d, currents_d).shape == (1,), "output shape incorrect" |
|
51
|
|
|
assert calculations.del_potential(potentials_d, currents_d).size == 1, "array size incorrect" |
|
52
|
|
|
np.testing.assert_almost_equal(calculations.del_potential(potentials_d, currents_d), 0.001, decimal=3), "value incorrect for data" |
|
53
|
|
|
return |
|
54
|
|
|
|
|
55
|
|
|
|
|
56
|
|
|
def test_half_wave_potential(): |
|
57
|
|
|
"""This function tests half_wave_potential() function.""" |
|
58
|
|
|
potentials = [0.500, 0.498, 0.499, 0.497] |
|
59
|
|
|
currents = [7.040, 6.998, 8.256, 8.286] |
|
60
|
|
|
potentials_d = pd.DataFrame(potentials) |
|
61
|
|
|
currents_d = pd.DataFrame(currents) |
|
62
|
|
|
|
|
63
|
|
|
assert type(calculations.half_wave_potential(potentials_d, currents_d)) == np.ndarray, "output is not an array" |
|
64
|
|
|
assert calculations.half_wave_potential(potentials_d, currents_d).size == 1, "out not correct size" |
|
65
|
|
|
np.testing.assert_almost_equal(calculations.half_wave_potential(potentials_d, currents_d), 0.0005, decimal=4), "value incorrect for data" |
|
66
|
|
|
return |
|
67
|
|
|
|
|
68
|
|
|
|
|
69
|
|
|
def test_peak_heights(): |
|
70
|
|
|
"""This function tests peak_heights() function.""" |
|
71
|
|
|
potentials = [0.500, 0.498, 0.499, 0.497] |
|
72
|
|
|
currents = [7.040, 6.998, 8.256, 8.286] |
|
73
|
|
|
potentials_d = pd.DataFrame(potentials) |
|
74
|
|
|
currents_d = pd.DataFrame(currents) |
|
75
|
|
|
|
|
76
|
|
|
assert type(calculations.peak_heights(potentials_d, currents_d)) == list, "output is not a list" |
|
77
|
|
|
assert len(calculations.peak_heights(potentials_d, currents_d)) == 2, "output list is not the correct length" |
|
78
|
|
|
np.testing.assert_almost_equal(calculations.peak_heights(potentials_d, currents_d)[0], 7.256, decimal=3), "max peak height incorrect for data" |
|
79
|
|
|
np.testing.assert_almost_equal(calculations.peak_heights(potentials_d, currents_d)[1], 4.998, decimal=3), "min peak height incorrect for data" |
|
80
|
|
|
return |
|
81
|
|
|
|
|
82
|
|
|
|
|
83
|
|
|
def test_peak_ratio(): |
|
84
|
|
|
"""This function tests peak_ratio() function.""" |
|
85
|
|
|
potentials = [0.500, 0.498, 0.499, 0.497] |
|
86
|
|
|
currents = [7.040, 6.998, 8.256, 8.286] |
|
87
|
|
|
potentials_d = pd.DataFrame(potentials) |
|
88
|
|
|
currents_d = pd.DataFrame(currents) |
|
89
|
|
|
|
|
90
|
|
|
assert type(calculations.peak_ratio(potentials_d, currents_d)) == np.ndarray, "output is not an array" |
|
91
|
|
|
assert len(calculations.peak_ratio(potentials_d, currents_d)) == 1, "output list is not the correct length" |
|
92
|
|
|
np.testing.assert_almost_equal(calculations.peak_ratio(potentials_d, currents_d), 1.451, decimal=3), "max peak height incorrect for data" |
|
93
|
|
|
return |
|
94
|
|
|
|