SimplificationTestCase.testUnionMixed()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 7

Duplication

Lines 7
Ratio 100 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
dl 7
loc 7
ccs 7
cts 7
cp 1
crap 1
rs 9.4285
1 1
import unittest
2
3 1
from ppp_datamodel.nodes import Triple as T
4 1
from ppp_datamodel.nodes import Missing as M
5 1
from ppp_datamodel.nodes import Resource as R
6 1
from ppp_datamodel.nodes import JsonldResource as JR
7 1
from ppp_datamodel.nodes.list_operators import *
8 1
from ppp_libmodule.simplification import simplify
9
10
11 1
class SimplificationTestCase(unittest.TestCase):
12 1
    def testList(self):
13 1
        self.assertEqual(simplify(List([R('a')])), R('a'))
14 1
    def testUnionTrivial(self):
15 1
        self.assertEqual(simplify(Union([])), List([]))
16 1
        self.assertEqual(simplify(Union([List([R('a')])])),
17
                R('a'))
18 1
    def testUnionResourceLists(self):
19 1
        t = Union([List([R('a'), R('b')]), List([R('c')])])
20 1
        t = simplify(t)
21 1
        self.assertIsInstance(t, List)
22 1
        self.assertEqual(set(t.list), {R('a'), R('b'), R('c')})
23 1 View Code Duplication
    def testUnionMixed(self):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
24 1
        t = Union([List([R('a'), R('b')]), T(M(), M(), M())])
25 1
        t = simplify(t)
26 1
        self.assertIsInstance(t, Union)
27 1
        self.assertEqual(t.list[0], T(M(), M(), M()))
28 1
        self.assertIsInstance(t.list[1], List)
29 1
        self.assertEqual(set(t.list[1].list), {R('a'), R('b')})
30
31 1
    def testIntersectionTrivial(self):
32 1
        self.assertEqual(simplify(Intersection([])), Intersection([]))
33 1
        self.assertEqual(simplify(Intersection([R('a')])),
34
                R('a'))
35 1
    def testIntersectionResourceLists(self):
36 1
        t = Intersection([List([R('a'), R('b')]), List([R('c'), R('a')])])
37 1
        t = simplify(t)
38 1
        self.assertEqual(t, R('a'))
39 1
        t = Intersection([List([R('a'), R('b'), R('c')]), List([R('c'), R('a')])])
40 1
        t = simplify(t)
41 1
        self.assertIn(t, (List([R('a'), R('c')]), List([R('c'), R('a')])))
42 1 View Code Duplication
    def testIntersectionMixed(self):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
43 1
        t = Intersection([List([R('a'), R('b')]), List([R('c'), R('a')]),
44
                         T(M(), M(), M())])
45 1
        t = simplify(t)
46 1
        self.assertIsInstance(t, Intersection)
47 1
        self.assertEqual(t.list[0], T(M(), M(), M()))
48 1
        self.assertEqual(t.list[1], R('a'))
49 1
    def testIntersectionJsonld(self):
50 1
        t = Intersection([
51
            List([
52
                JR('a', graph={'@id': 'foo'}),
53
                JR('b', graph={'@id': 'bar'})
54
                ]),
55
            List([
56
                JR('b', graph={'@id': 'baz'}),
57
                JR('d', graph={'@id': 'foo'})
58
                ])])
59 1
        t = simplify(t)
60
        self.assertEqual(t, JR('e', graph={'@id': 'foo'}))
61