Repository navigation
Expand file tree
/
Copy pathtest_simplification.py
More file actions
60 lines (56 loc) · 2.39 KB
/
Copy pathtest_simplification.py
File metadata and controls
60 lines (56 loc) · 2.39 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
import unittest
from ppp_datamodel.nodes import Triple as T
from ppp_datamodel.nodes import Missing as M
from ppp_datamodel.nodes import Resource as R
from ppp_datamodel.nodes import JsonldResource as JR
from ppp_datamodel.nodes.list_operators import *
from ppp_libmodule.simplification import simplify
class SimplificationTestCase(unittest.TestCase):
def testList(self):
self.assertEqual(simplify(List([R('a')])), R('a'))
def testUnionTrivial(self):
self.assertEqual(simplify(Union([])), List([]))
self.assertEqual(simplify(Union([List([R('a')])])),
R('a'))
def testUnionResourceLists(self):
t = Union([List([R('a'), R('b')]), List([R('c')])])
t = simplify(t)
self.assertIsInstance(t, List)
self.assertEqual(set(t.list), {R('a'), R('b'), R('c')})
def testUnionMixed(self):
t = Union([List([R('a'), R('b')]), T(M(), M(), M())])
t = simplify(t)
self.assertIsInstance(t, Union)
self.assertEqual(t.list[0], T(M(), M(), M()))
self.assertIsInstance(t.list[1], List)
self.assertEqual(set(t.list[1].list), {R('a'), R('b')})
def testIntersectionTrivial(self):
self.assertEqual(simplify(Intersection([])), Intersection([]))
self.assertEqual(simplify(Intersection([R('a')])),
R('a'))
def testIntersectionResourceLists(self):
t = Intersection([List([R('a'), R('b')]), List([R('c'), R('a')])])
t = simplify(t)
self.assertEqual(t, R('a'))
t = Intersection([List([R('a'), R('b'), R('c')]), List([R('c'), R('a')])])
t = simplify(t)
self.assertIn(t, (List([R('a'), R('c')]), List([R('c'), R('a')])))
def testIntersectionMixed(self):
t = Intersection([List([R('a'), R('b')]), List([R('c'), R('a')]),
T(M(), M(), M())])
t = simplify(t)
self.assertIsInstance(t, Intersection)
self.assertEqual(t.list[0], T(M(), M(), M()))
self.assertEqual(t.list[1], R('a'))
def testIntersectionJsonld(self):
t = Intersection([
List([
JR('a', graph={'@id': 'foo'}),
JR('b', graph={'@id': 'bar'})
]),
List([
JR('b', graph={'@id': 'baz'}),
JR('d', graph={'@id': 'foo'})
])])
t = simplify(t)
self.assertEqual(t, JR('e', graph={'@id': 'foo'}))