-
Notifications
You must be signed in to change notification settings - Fork 8
/
test_pdf_bookmark.py
129 lines (105 loc) · 2.36 KB
/
test_pdf_bookmark.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
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
# pylint: disable=missing-docstring
import pytest
from pdf_bookmark import InvalidRomanNumeralError
from pdf_bookmark import RomanOutOfRangeError
from pdf_bookmark import roman_to_arabic
from pdf_bookmark import arabic_to_roman
from pdf_bookmark import InvalidLettersNumeralError
from pdf_bookmark import letters_to_arabic
from pdf_bookmark import arabic_to_letters
INVALID_ROMAN = (
'',
'ii',
'IIIII',
'ID',
'XM',
'12345',
'jflaiffj',
'+=_-&^%#!$%#*&)~`,.><',
)
INVALID_ROMAN_VALUE = (
-100000,
-1,
5000,
5001,
5002,
10000,
)
ROMAN_PAIRS = (
(0, 'N'),
(1, 'I'),
(2, 'II'),
(3, 'III'),
(4, 'IV'),
(5, 'V'),
(9, 'IX'),
(12, 'XII'),
(16, 'XVI'),
(29, 'XXIX'),
(44, 'XLIV'),
(45, 'XLV'),
(68, 'LXVIII'),
(83, 'LXXXIII'),
(97, 'XCVII'),
(99, 'XCIX'),
(400, 'CD'),
(500, 'D'),
(501, 'DI'),
(649, 'DCXLIX'),
(798, 'DCCXCVIII'),
(891, 'DCCCXCI'),
(1000, 'M'),
(1004, 'MIV'),
(1006, 'MVI'),
(1023, 'MXXIII'),
(2014, 'MMXIV'),
(3999, 'MMMCMXCIX'),
(4999, 'MMMMCMXCIX'),
)
def test_invalid_roman():
for roman in INVALID_ROMAN:
with pytest.raises(InvalidRomanNumeralError):
roman_to_arabic(roman)
def test_roman_to_arabic():
for arabic, roman in ROMAN_PAIRS:
assert roman_to_arabic(roman) == arabic
def test_out_of_range_roman():
for arabic in INVALID_ROMAN_VALUE:
with pytest.raises(RomanOutOfRangeError):
arabic_to_roman(arabic)
def test_arabic_to_roman():
for arabic, roman in ROMAN_PAIRS:
assert arabic_to_roman(arabic) == roman
INVALID_LETTERS = (
'0',
'0342',
'a',
'ABC',
'AAAAAA8',
'9BBBB',
'&*-+#',
'12345',
'jflaiffj',
'+=_-&^%#!$%#*&)~`,.><',
)
LETTERS_PAIRS = (
(0, ''),
(1, 'A'),
(2, 'B'),
(3, 'C'),
(8, 'H'),
(26, 'Z'),
(27, 'AA'),
(52, 'ZZ'),
(106, 'BBBBB'),
)
def test_invalid_letter():
for letters in INVALID_LETTERS:
with pytest.raises(InvalidLettersNumeralError):
letters_to_arabic(letters)
def test_letters_to_arabic():
for arabic, letters in LETTERS_PAIRS:
assert letters_to_arabic(letters) == arabic
def test_arabic_to_letters():
for arabic, letters in LETTERS_PAIRS:
assert arabic_to_letters(arabic) == letters