-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_order.py
More file actions
74 lines (60 loc) · 2.19 KB
/
test_order.py
File metadata and controls
74 lines (60 loc) · 2.19 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
from unittest import TestCase
import numpy as np
import pytest
from numpy.testing import assert_array_equal
from foapy import order
from foapy.exceptions import Not1DArrayException
class TestOrder(TestCase):
"""
Test list of array sequence
"""
def test_string_values(self):
X = ["a", "b", "a", "c", "d"]
expected = np.array([0, 1, 0, 2, 3])
exists = order(X)
assert_array_equal(expected, exists)
def test_int_values(self):
X = [1, 2, 2, 3, 4, 1]
expected = np.array([0, 1, 1, 2, 3, 0])
exists = order(X)
assert_array_equal(expected, exists)
def test_void(self):
X = []
expected = np.array([])
exists = order(X)
assert_array_equal(expected, exists)
def test_single_value(self):
X = ["E"]
expected = np.array([0])
exists = order(X)
assert_array_equal(expected, exists)
def test_with_d2_array_exception(self):
X = [[[2, 2, 2], [2, 2, 2]]]
with pytest.raises(Not1DArrayException) as e_info:
order(X)
self.assertEqual(
"Incorrect array form. Expected d1 array, exists 2",
e_info.message,
)
def test_with_d3_array_exception(self):
X = [[[1], [3]], [[6], [9]], [[6], [3]]]
with pytest.raises(Not1DArrayException) as e_info:
order(X)
self.assertEqual(
"Incorrect array form. Expected d1 array, exists 3",
e_info.message,
)
def test_with_return_alphabet(self):
X = ["d", "e", "e", "c", "a", "d"]
expected_alphabet = ["d", "e", "c", "a"]
expected_array = [0, 1, 1, 2, 3, 0]
exists_array, exists_alphabet = order(X, True)
assert_array_equal(expected_alphabet, exists_alphabet)
assert_array_equal(expected_array, exists_array)
def test_reverse(self):
length = np.random.randint(1, 50000)
alphabet = np.arange(0, np.fix(length * 0.2), dtype=int)
X = np.random.choice(alphabet, length)
exists_order, exists_alphabet = order(X, True)
X_restore = exists_alphabet[exists_order]
assert_array_equal(X, X_restore)