Repository navigation
Expand file tree
/
Copy pathtest_intervals.py
More file actions
164 lines (137 loc) · 5.46 KB
/
Copy pathtest_intervals.py
File metadata and controls
164 lines (137 loc) · 5.46 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
from unittest import TestCase
import numpy as np
import pytest
from helpers.intervals import intervals, mode
from numpy.testing import assert_array_equal
from foapy import binding
class TestIntervals(TestCase):
"""
Test list of array intervals
"""
def test_int_start_none(self):
X = [2, 4, 2, 2, 4]
expected = np.array([2, 1, 3])
exists = intervals(X, binding.start, mode.lossy)
assert_array_equal(expected, exists)
def test_void(self):
X = []
expected = np.array([])
exists = intervals(X, binding.start, mode.lossy)
assert_array_equal(expected, exists)
def test_int_end_none(self):
X = [2, 4, 2, 2, 4]
expected = np.array([2, 3, 1])
exists = intervals(X, binding.end, mode.lossy)
assert_array_equal(np.sort(expected), np.sort(exists))
def test_int_start_normal_1(self):
X = [2, 4, 2, 2, 4]
expected = np.array([1, 2, 2, 1, 3])
exists = intervals(X, binding.start, mode.normal)
assert_array_equal(expected, exists)
def test_string_start_normal_1(self):
X = ["a", "b", "a", "c", "d"]
expected = np.array([1, 2, 2, 4, 5])
exists = intervals(X, binding.start, mode.normal)
assert_array_equal(expected, exists)
def test_string_start_normal_2(self):
X = ["a", "c", "c", "e", "d", "a"]
expected = np.array([1, 2, 1, 4, 5, 5])
exists = intervals(X, binding.start, mode.normal)
assert_array_equal(expected, exists)
def test_int_start_normal_2(self):
X = [0, 1, 2, 3, 4]
expected = np.array([1, 2, 3, 4, 5])
exists = intervals(X, binding.start, mode.normal)
assert_array_equal(expected, exists)
def test_single_value_1(self):
X = ["E"]
expected = np.array([1])
exists = intervals(X, binding.start, mode.normal)
assert_array_equal(expected, exists)
def test_string_start_normal_3(self):
X = ["E", "E", "E"]
expected = np.array([1, 1, 1])
exists = intervals(X, binding.start, mode.normal)
assert_array_equal(expected, exists)
def test_int_end_normal_1(self):
X = [2, 4, 2, 2, 4]
expected = np.array([2, 3, 1, 2, 1])
exists = intervals(X, binding.end, mode.normal)
assert_array_equal(expected, exists)
def test_int_end_normal_2(self):
X = [0, 1, 2, 3, 4]
expected = np.array([5, 4, 3, 2, 1])
exists = intervals(X, binding.end, mode.normal)
assert_array_equal(expected, exists)
def test_int_start_cycle(self):
X = [2, 4, 2, 2, 4]
expected = np.array([2, 2, 2, 1, 3])
exists = intervals(X, binding.start, mode.cycle)
assert_array_equal(expected, exists)
def test_int_end_cycle(self):
X = [2, 4, 2, 2, 4]
expected = np.array([2, 3, 1, 2, 2])
exists = intervals(X, binding.end, mode.cycle)
assert_array_equal(expected, exists)
def test_dna_start_normal(self):
X = ["ATC", "CTG", "ATC"]
expected = np.array([1, 2, 2])
exists = intervals(X, binding.start, mode.normal)
assert_array_equal(expected, exists)
def test_int_start_redundant(self):
X = [2, 4, 2, 2, 4]
expected = np.array([1, 2, 2, 1, 3, 2, 1])
exists = intervals(X, binding.start, mode.redundant)
assert_array_equal(expected, exists)
def test_int_end_redundant(self):
X = [2, 4, 2, 2, 4]
expected = np.array([1, 2, 2, 3, 1, 2, 1])
exists = intervals(X, binding.end, mode.redundant)
assert_array_equal(np.sort(expected), np.sort(exists))
def test_single_redundant(self):
X = ["E"]
expected = np.array([1, 1])
exists = intervals(X, binding.start, mode.redundant)
assert_array_equal(expected, exists)
def test_string_start_redundant(self):
X = ["E", "E", "E"]
expected = np.array([1, 1, 1, 1])
exists = intervals(X, binding.start, mode.redundant)
assert_array_equal(expected, exists)
def test_dna_start_redundant(self):
X = ["ATC", "CTG", "ATC"]
expected = np.array([1, 2, 2, 1, 2])
exists = intervals(X, binding.start, mode.redundant)
assert_array_equal(np.sort(expected), np.sort(exists))
def test_ValueError_mode_1(self):
X = [2, 4, 2, 2, 4]
with pytest.raises(ValueError) as e_info:
intervals(X, 2, 5)
self.assertEqual(
"Invalid mode value. Use mode.lossy,normal,cycle or redundant.",
e_info.message,
)
def test_ValueError_mode_2(self):
X = [2, 4, 2, 2, 4]
with pytest.raises(ValueError) as e_info:
intervals(X, binding.start, 10)
self.assertEqual(
"Invalid mode value. Use mode.lossy,normal,cycle or redundant.",
e_info.message,
)
def test_ValueError_binding_1(self):
X = [2, 4, 2, 2, 4]
with pytest.raises(ValueError) as e_info:
intervals(X, 3, 4)
self.assertEqual(
"Invalid binding value. Use binding.start or binding.end.",
e_info.message,
)
def test_ValueError_binding_2(self):
X = [2, 4, 2, 2, 4]
with pytest.raises(ValueError) as e_info:
intervals(X, 3, mode.redundant)
self.assertEqual(
"Invalid binding value. Use binding.start or binding.end.",
e_info.message,
)