-
Notifications
You must be signed in to change notification settings - Fork 92
/
test_utils.py
60 lines (51 loc) · 2.28 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
# -*- coding: utf-8 -*-
"""
Unit tests for the synchrofact detection app
"""
import unittest
import neo
import numpy as np
import quantities as pq
from elephant import utils
from numpy.testing import assert_array_equal
class TestUtils(unittest.TestCase):
def test_check_neo_consistency(self):
self.assertRaises(TypeError,
utils.check_neo_consistency,
[], object_type=neo.SpikeTrain)
self.assertRaises(TypeError,
utils.check_neo_consistency,
[neo.SpikeTrain([1]*pq.s, t_stop=2*pq.s),
np.arange(2)], object_type=neo.SpikeTrain)
self.assertRaises(ValueError,
utils.check_neo_consistency,
[neo.SpikeTrain([1]*pq.s,
t_start=1*pq.s,
t_stop=2*pq.s),
neo.SpikeTrain([1]*pq.s,
t_start=0*pq.s,
t_stop=2*pq.s)],
object_type=neo.SpikeTrain)
self.assertRaises(ValueError,
utils.check_neo_consistency,
[neo.SpikeTrain([1]*pq.s, t_stop=2*pq.s),
neo.SpikeTrain([1]*pq.s, t_stop=3*pq.s)],
object_type=neo.SpikeTrain)
self.assertRaises(ValueError,
utils.check_neo_consistency,
[neo.SpikeTrain([1]*pq.ms, t_stop=2000*pq.ms),
neo.SpikeTrain([1]*pq.s, t_stop=2*pq.s)],
object_type=neo.SpikeTrain)
def test_round_binning_errors(self):
n_bins = utils.round_binning_errors(0.999999, tolerance=1e-6)
self.assertEqual(n_bins, 1)
self.assertEqual(utils.round_binning_errors(0.999999, tolerance=None),
0)
array = np.array([0, 0.7, 1 - 1e-8, 1 - 1e-9])
corrected = utils.round_binning_errors(array.copy())
assert_array_equal(corrected, [0, 0, 1, 1])
assert_array_equal(
utils.round_binning_errors(array.copy(), tolerance=None),
[0, 0, 0, 0])
if __name__ == '__main__':
unittest.main()