Completed
Push — master ( 23b608...8098ec )
by Thomas
01:16
created

SimplificationTestCase   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 50
Duplicated Lines 28 %

Test Coverage

Coverage 100%

Importance

Changes 5
Bugs 0 Features 0
Metric Value
c 5
b 0
f 0
dl 14
loc 50
ccs 38
cts 38
cp 1
rs 10
wmc 8

8 Methods

Rating   Name   Duplication   Size   Complexity  
A testUnionTrivial() 0 4 1
A testIntersectionTrivial() 0 4 1
A testUnionResourceLists() 0 5 1
A testIntersectionJsonld() 0 12 1
A testIntersectionMixed() 7 7 1
A testIntersectionResourceLists() 0 7 1
A testUnionMixed() 7 7 1
A testList() 0 2 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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