forked from fhirschmann/rdp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
62 lines (52 loc) · 1.76 KB
/
tests.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
import unittest
import numpy as np
from numpy.testing import assert_array_equal as assertAE
from rdp import rdp
class RDPTest(unittest.TestCase):
def test_two(self):
"""
Point sequence with only two elements.
"""
assertAE(rdp(np.array([[0, 0], [4, 4]])),
np.array([[0, 0], [4, 4]]))
def test_hor(self):
"""
Horizontal line.
"""
assertAE(rdp(np.array([0, 0, 1, 0, 2, 0, 3, 0, 4, 0]).reshape(5, 2)),
np.array([0, 0, 4, 0]).reshape(2, 2))
def test_ver(self):
"""
Vertical line.
"""
assertAE(rdp(np.array([0, 0, 0, 1, 0, 2, 0, 3, 0, 4]).reshape(5, 2)),
np.array([0, 0, 0, 4]).reshape(2, 2))
def test_diag(self):
"""
Diagonal line.
"""
assertAE(rdp(np.array([0, 0, 1, 1, 2, 2, 3, 3, 4, 4]).reshape(5, 2)),
np.array([0, 0, 4, 4]).reshape(2, 2))
def test_eps0(self):
"""
Epsilon being to small to be simplified.
"""
assertAE(rdp(np.array([0, 0, 5, 1, 10, 1]).reshape(3, 2)),
np.array([0, 0, 5, 1, 10, 1]).reshape(3, 2))
def test_eps1(self):
"""
Epsilon large enough to be simplified.
"""
assertAE(rdp(np.array([0, 0, 5, 1, 10, 1]).reshape(3, 2), 1),
np.array([0, 0, 10, 1]).reshape(2, 2))
def test_L0(self):
"""
Point sequence which has the form of a L.
"""
assertAE(rdp(np.array([5, 0, 4, 0, 3, 0, 3, 1, 3, 2]).reshape(5, 2)),
np.array([5, 0, 3, 0, 3, 2]).reshape(3, 2))
def test_nn(self):
"""
Non-numpy interface to rdp.
"""
self.assertEqual(rdp([[0, 0], [2, 2], [4, 4]]), [[0, 0], [4, 4]])