|
a |
|
b/tests/test_sampen.py |
|
|
1 |
import numpy |
|
|
2 |
import os |
|
|
3 |
import unittest |
|
|
4 |
|
|
|
5 |
from pyeeg import samp_entropy |
|
|
6 |
|
|
|
7 |
|
|
|
8 |
class SampEnTests(unittest.TestCase): |
|
|
9 |
def test_sampen_against_predictable_sequence(self): |
|
|
10 |
data = numpy.asarray([10, 20] * 2000) |
|
|
11 |
self.assertAlmostEqual( |
|
|
12 |
samp_entropy(data, 2, 0.2), |
|
|
13 |
0.0, |
|
|
14 |
places=2 |
|
|
15 |
) |
|
|
16 |
|
|
|
17 |
def test_sampen_against_original_c_test_data(self): |
|
|
18 |
"""Use test data from |
|
|
19 |
http://www.physionet.org/physiotools/sampen/c/sampentest.txt |
|
|
20 |
""" |
|
|
21 |
dir = os.path.dirname(__file__) |
|
|
22 |
file_path = os.path.join(dir, './demo_data/sampentest.txt') |
|
|
23 |
data = [] |
|
|
24 |
with open(file_path, 'r') as file: |
|
|
25 |
for row in file: |
|
|
26 |
data.append(float(row.strip())) |
|
|
27 |
|
|
|
28 |
self.assertEqual( |
|
|
29 |
samp_entropy(numpy.asarray(data), 2, 0.2), |
|
|
30 |
2.1233284920357112 |
|
|
31 |
) |
|
|
32 |
|
|
|
33 |
|
|
|
34 |
if __name__ == '__main__': |
|
|
35 |
unittest.main() |