-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_generate_forms.py
More file actions
54 lines (48 loc) · 1.63 KB
/
test_generate_forms.py
File metadata and controls
54 lines (48 loc) · 1.63 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
import unittest
import generate_forms
import os
class TestParsing(unittest.TestCase):
grammar_file = 'grammar.fcfg'
out_file = 'testing.txt'
def test_intransitive(self):
"""
Checks intransitive sentences.
"""
rubric = [
("Alice walks", "walk ( alice )"),
("Everyone walks", "all x . ( person ( x ) -> walk ( x ) )"),
("Someone walks", "exists x . ( person ( x ) & walk ( x ) )")
]
self.assertEqual(
[r[1] for r in rubric],
generate_forms._generate_forms([r[0] for r in rubric], self.grammar_file)
)
def test_transitive(self):
"""
Checks transitive sentences.
"""
rubric = [
("Claire sees Alice", "see ( claire , alice )"),
("Claire sees Everyone", "all x . ( person ( x ) -> see ( claire , x ) )"),
("Claire sees Someone", "exists x . ( person ( x ) & see ( claire , x ) )"),
("Everyone sees Claire", "all x . ( person ( x ) -> see ( x , claire ) )"),
("Someone sees Claire", "exists x . ( person ( x ) & see ( x , claire ) )"),
("Bob sees Himself", "see ( bob , bob )"),
("Everyone sees Himself", "all x . ( person ( x ) -> see ( x , x ) )"),
("Someone sees Himself", "exists x . ( person ( x ) & see ( x , x ) )")
]
self.assertEqual(
[r[1] for r in rubric],
generate_forms._generate_forms([r[0] for r in rubric], self.grammar_file)
)
def test_whitespace(self):
"""
Checks for extranous whitespace or formatting in the generate output file.
"""
generate_forms.generate_f(self.grammar_file, self.out_file)
with open(self.out_file, 'r') as f:
contents = f.readlines()
self.assertNotIn(' ', contents)
os.remove(self.out_file)
if __name__ == '__main__':
unittest.main()