-
Notifications
You must be signed in to change notification settings - Fork 0
/
unittests.py
136 lines (97 loc) · 4.17 KB
/
unittests.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
130
131
132
133
134
135
136
# -*- coding: utf-8 -*-
import unittest
import model
import endings
class WordsFromText(unittest.TestCase):
def test_parsing(self):
x = model.words_from_text("!Abc &§$def,gh iL..m\r\n\tx")
self.failUnlessEqual(x, {'Abc', 'def', 'gh', 'iL', 'm', 'x'})
def test_char_only(self):
x = model.words_from_text("!.%)(%/&(/!§)=)")
self.failUnlessEqual(x, set())
def test_empty_text(self):
x = model.words_from_text("")
self.failUnlessEqual(x, set())
def test_duplicates(self):
x = model.words_from_text("A A A B C")
self.failUnlessEqual(x, {"A", "B", "C"})
class WordWithEndings(unittest.TestCase):
def test_connecting(self):
x = model.word_with_endings("abc", {'', 'b', 'aBc'})
self.failUnlessEqual(x, {'abc', 'abcb', 'abcaBc'})
def test_empty_wordlist(self):
x = model.word_with_endings(set(), {"a", "b"})
self.failUnlessEqual(x, set())
def test_empty_endings(self):
x = model.word_with_endings("x", set())
self.failUnlessEqual(x, {"x"})
def test_empty_both(self):
x = model.word_with_endings(set(), set())
self.failUnlessEqual(x, set())
def test_duplicates(self):
word = "abc"
x = model.word_with_endings(word, {"x", "x", "y"})
self.failUnlessEqual(x, {"abcx", "abcy"})
class WordsWithEndings(unittest.TestCase):
def test_basic(self):
words = ['a', 'b', 'ABC']
x = model.words_with_endings(words, {'', 'x', 'XX'})
self.failUnlessEqual(x, {'a', 'ax', 'aXX', 'b', 'bx', 'bXX',
'ABC', 'ABCx', 'ABCXX'})
def test_empty_wordlist(self):
x = model.words_with_endings(set(), {"a", "b", "c"})
self.failUnlessEqual(x, set())
def test_empty_endings(self):
x = model.words_with_endings({"a", "b", "c"}, set())
self.failUnlessEqual(x, {"a", "b", "c"})
def test_empty_both(self):
x = model.words_with_endings(set(), set())
self.failUnlessEqual(x, set())
def test_duplicates(self):
x = model.words_with_endings(["a", "b", "b"], ["1", "2"])
self.failUnlessEqual(x, {"a1", "a2", "b1", "b2"})
class MissingVocabulary(unittest.TestCase):
def test_basic(self):
x = model.missing_vocabulary(
{"a1", "a2", "a3"}, {"a", "b"}, {"1", "2"})
self.failUnlessEqual(x, {"a3"})
def test_basic_case(self):
x = model.missing_vocabulary(
{"A1", "A2", "A3"}, {"A", "B"}, {"1", "2"})
self.failUnlessEqual(x, {'a3'})
def test_empty_words(self):
x = model.missing_vocabulary(set(), {"a", "b"}, {"1", "2"})
self.failUnlessEqual(x, set())
def test_empty_basicforms(self):
x = model.missing_vocabulary({"a", "b", "c", "d"}, set(), {"a", "b"})
self.failUnlessEqual(x, {"a", "b", "c", "d"})
def test_empty_endings(self):
x = model.missing_vocabulary({"a", "b", "c", "d"}, {"c", "d"}, set())
self.failUnlessEqual(x, {"a", "b"})
def test_only_words(self):
x = model.missing_vocabulary({"a", "b", "c", "d"}, set(), set())
self.failUnlessEqual(x, {"a", "b", "c", "d"})
def test_words_and_basicforms(self):
x = model.missing_vocabulary({"a", "b", "c", "d"}, {"a", "b"}, set())
self.failUnlessEqual(x, {"c", "d"})
def test_words_and_endings(self):
x = model.missing_vocabulary({"a", "b", "c", "d"}, set(), {"c", "d"})
self.failUnlessEqual(x, {"a", "b", "c", "d"})
def test_empty_args(self):
x = model.missing_vocabulary(set(), set(), set())
self.failUnlessEqual(x, set())
def test_word_is_in_vocab(self):
x = model.missing_vocabulary({"xxx", "yyy"}, {"xxx", "yyy"}, set())
self.failUnlessEqual(x, set())
class ParsingTests(unittest.TestCase):
def setUp(self):
endings.save(['abc', '# def', '', ' ', ' test', ' ##'],
'test_endings.txt')
def test_load_endings(self):
x = endings.load('test_endings.txt')
self.failUnlessEqual(x, ['abc', 'test'])
def tearDown(self):
import os
os.remove('test_endings.txt')
if __name__ == '__main__':
unittest.main()