-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
95 lines (73 loc) · 2.7 KB
/
test.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
95
import unittest
import maths
import time
import file
"""
This file contains all of the unit tests for functions of the app.
Tests cover file.py and maths.py.
Last Updated: 02/10/2020
Author: Nathan Gillbanks
Contributors: Andrew Durnford
"""
class TestMethods(unittest.TestCase):
# **************** file.py ******************
# test read .bin file
def test_binRead(self):
data = file.binary_Read("test/UnitTest.bin")
self.assertTrue(not data is None)
def test_binReadException(self):
with self.assertRaises(OSError):
data = file.binary_Read("test/NotARealFile.bin")
# test read .csv file
def test_csvRead(self):
data = file.binary_Read("test/UnitTest.csv")
self.assertTrue(not data is None)
def test_csvReadException(self):
with self.assertRaises(OSError):
data = file.csv_Read("test/NotARealFile.csv")
# test read .data file
def test_csvRead(self):
data = file.data_read("test/UnitTest.data")
self.assertTrue(not data is None)
def test_csvReadException(self):
with self.assertRaises(OSError):
data = file.data_read("test/NotARealFile.data")
# test read file 1
def test_readFile1(self):
post_calc = 1
data = file.readFile("test/unitTest.data", post_calc)
self.assertTrue(not data is None)
# test read file 2
def test_readFile2(self):
post_calc = 2
self.assertFalse(post_calc < 1)
self.assertFalse(post_calc > 2)
self.assertTrue(post_calc == 1 or post_calc == 2)
post_calc = 1
data = file.readFile("test/unitTest_Post.data", post_calc)
self.assertTrue(not data is None)
# **************** maths.py *****************
def test_maths(self):
data = file.readFile("./data/5ppm.data", 0)
v = data.iloc[:, 0].values
i = data.iloc[:, 1].values
# test blanking_first_samples
v, i = maths.blanking_first_samples(4000, v, i)
self.assertEqual(len(i), len(v))
# test get_time_values
f, t = maths.get_time_values(i, 44100)
self.assertEqual(len(f), len(t))
# test get_ienv
harmonic = maths.get_ienv(i, 60, 1, 10, 8000, 10, t)
self.assertTrue(not harmonic is None)
# test magnitude_of_current
Imag = maths.magnitude_of_current(i, i.size)
self.assertTrue(not Imag is None)
# test cumulative_sum_ienv
int_ienv = maths.cumulative_sum_ienv(harmonic)
self.assertTrue(not int_ienv is None)
# test filter_ienv
ienv_filtered = maths.filter_ienv(harmonic, 200)
self.assertTrue(not ienv_filtered is None)
if __name__ == '__main__':
unittest.main()