Completed
Push — master ( d060d7...4b3449 )
by Siro Díaz
02:14
created

SimpleLinkedListTest   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 140
Duplicated Lines 64.29 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 14
lcom 1
cbo 2
dl 90
loc 140
rs 10
c 0
b 0
f 0

13 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 3 1
A testSize() 0 3 1
A testEmpty() 0 3 1
A testPush() 10 10 1
A testInsert() 23 23 1
A testDelete() 13 13 1
A testShift() 10 10 1
A testPop() 0 4 1
A testUnshift() 14 14 1
A testGet() 0 8 1
A testGetAll() 0 13 2
A testToArray() 10 10 1
A testClear() 10 10 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
<?php
2
3
namespace DataStructures\Tests\Lists;
4
5
use DataStructures\Lists\SimpleLinkedList;
6
use PHPUnit\Framework\TestCase;
7
8
class SimpleLinkedListTest extends TestCase {
9
    private $list;
10
11
    public function setUp() {
12
        $this->list = new SimpleLinkedList();
13
    }
14
15
    public function testSize() {
16
        $this->assertEquals($this->list->size(), 0);
17
    }
18
19
    public function testEmpty() {
20
        $this->assertTrue($this->list->empty());
21
    }
22
23 View Code Duplication
    public function testPush() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
24
        $this->list->push(20);
25
        $this->assertEquals(1, $this->list->size());
26
        $this->assertEquals(20, $this->list->get(0));
27
        $this->list->push(true);
28
        $this->assertEquals(2, $this->list->size());
29
        $this->assertTrue($this->list->get(1));
30
        $this->list->push(30);
31
        $this->assertEquals(30, $this->list->get(2));
32
    }
33
34 View Code Duplication
    public function testInsert() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
35
        $this->list->insert(0, 100);
36
        $this->assertEquals(100, $this->list->get(0));
37
        $this->assertEquals(1, $this->list->size());
38
39
        $this->list->insert(0, 200);
40
        $this->assertEquals(2, $this->list->size());
41
        $this->assertEquals(200, $this->list->get(0));
42
        $this->assertEquals(100, $this->list->get(1));
43
44
        $this->list->insert(1, 300);
45
        $this->assertEquals(3, $this->list->size());
46
        $this->assertEquals(200, $this->list->get(0));
47
        $this->assertEquals(300, $this->list->get(1));
48
        $this->assertEquals(100, $this->list->get(2));
49
        
50
        /*
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
51
        for($i = 0; $i < 100; $i++) {
52
            $this->list->insert($i, $i + 1);
53
            $this->assertEquals($i + 1, $this->list->get($i));
54
        }
55
        */
56
    }
57
    
58 View Code Duplication
    public function testDelete() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
59
        $this->assertNull($this->list->delete(10));
60
        $this->list->push(20);
61
        $this->list->push(true);
62
        $this->list->push(15);
63
        $this->list->push(3.14);
64
        $this->list->push("string");
65
        $this->assertEquals(3.14, $this->list->delete(3));
66
        $this->assertEquals(4, $this->list->size());
67
        $this->assertEquals(true, $this->list->delete(1));
68
        $this->assertEquals(false, $this->list->empty());
69
        $this->assertEquals(20, $this->list->delete(0));
70
    }
71
72 View Code Duplication
    public function testShift() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
73
        $this->assertNull($this->list->shift());
74
        $this->list->push(20);
75
        $this->list->push(true);
76
        $this->assertEquals(20, $this->list->shift());
77
        $this->assertEquals(1, $this->list->size());
78
        $this->assertEquals(true, $this->list->shift());
79
        $this->assertEquals(true, $this->list->empty());
80
        $this->assertNull($this->list->shift());
81
    }
82
83
    public function testPop() {
84
        //TODO 
85
        $this->assertTrue(true);
86
    }
87
88 View Code Duplication
    public function testUnshift() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
89
        $this->list->unshift(999);
90
        $this->assertEquals(1, $this->list->size());
91
        $this->assertEquals(999, $this->list->get(0));
92
        $this->list->unshift(888);
93
        $this->assertEquals(2, $this->list->size());
94
        $this->assertEquals(888, $this->list->get(0));
95
        $this->assertEquals(999, $this->list->get(1));
96
        $this->list->unshift(777);
97
        $this->assertEquals(3, $this->list->size());
98
        $this->assertEquals(777, $this->list->get(0));
99
        $this->assertEquals(888, $this->list->get(1));
100
        $this->assertEquals(999, $this->list->get(2));
101
    }
102
103
    public function testGet() {
104
        $this->list->push(20);
105
        $this->list->push(true);
106
        $this->list->push(15);
107
        $this->list->push(3.14);
108
        $this->list->push("string");
109
        $this->assertTrue(true);
110
    }
111
112
    public function testGetAll() {
113
        $this->list->push(20);
114
        $this->list->push(true);
115
        $this->list->push(15);
116
        $this->list->push(3.14);
117
        $this->list->push("string");
118
        $data = [];
119
        foreach($this->list->getAll() as $node) {
120
            $data[] = $node;
121
        }
122
        $this->assertCount(5, $data);
123
        $this->assertSame([20, true, 15, 3.14, "string"], $data);
124
    }
125
126 View Code Duplication
    public function testToArray() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
127
        $this->list->push(20);
128
        $this->list->push(true);
129
        $this->list->push(15);
130
        $this->list->push(3.14);
131
        $this->list->push("string");
132
        $this->list->pop();
133
        $nodes = $this->list->toArray();
134
        $this->assertSame([20, true, 15, 3.14], $nodes);
135
    }
136
137 View Code Duplication
    public function testClear() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
138
        $this->list->push(20);
139
        $this->list->push(true);
140
        $this->list->push(15);
141
        $this->list->push(3.14);
142
        $this->list->push("string");
143
        $this->list->clear();
144
        $this->assertEmpty($this->list->toArray());
145
        $this->assertEquals($this->list->size(), 0);
146
    }
147
}