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

StackTest::testPush()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 9

Duplication

Lines 10
Ratio 100 %

Importance

Changes 0
Metric Value
dl 10
loc 10
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 9
nc 1
nop 0
1
<?php
2
3
namespace DataStructures\Tests\Lists;
4
5
use DataStructures\Exceptions\FullException;
6
use DataStructures\Lists\Stack;
7
use PHPUnit\Framework\TestCase;
8
9
class StackTest extends TestCase {
10
    private $stack;
11
12
    public function testContructMaxSize() {
13
        $this->expectException(\InvalidArgumentException::class);
14
        $this->stack = new Stack(-1);
15
    }
16
    
17 View Code Duplication
    public function testPushWithMaxSize() {
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...
18
        $this->stack = new Stack(5);
19
        $this->stack->push(1);
20
        $this->assertEquals($this->stack->peek(), 1);
21
        $this->stack->push(2);
22
        $this->assertEquals($this->stack->peek(), 2);
23
        $this->stack->push(3);
24
        $this->assertEquals($this->stack->peek(), 3);
25
        $this->stack->push(4);
26
        $this->stack->push(5);
27
        $this->expectException(FullException::class);
28
        $this->stack->push(6);
29
    }
30
    
31 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...
32
        $this->stack = new Stack();
33
        $this->stack->push(1);
34
        $this->stack->push(2);
35
        $this->stack->push(3);
36
        $this->stack->push(4);
37
        $this->stack->push(5);
38
        $this->assertEquals($this->stack->size(), 5);
39
        $this->assertEquals($this->stack->peek(), 5);
40
    }
41
    
42 View Code Duplication
    public function testPop() {
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...
43
        $this->stack = new Stack();
44
        $this->assertNull($this->stack->pop());
45
        $this->stack->push(1);
46
        $this->stack->push(2);
47
        $this->stack->push(3);
48
        $this->stack->push(4);
49
        $this->stack->push(5);
50
        $this->assertEquals($this->stack->pop(), 5);
51
        $this->assertEquals($this->stack->pop(), 4);
52
        $this->assertEquals($this->stack->pop(), 3);
53
        $this->assertEquals($this->stack->pop(), 2);
54
        $this->assertEquals($this->stack->pop(), 1);
55
    }
56
    
57
    public function testDequeueWithMaxSize() {
58
        $this->stack = new Stack(4);
59
        $this->stack->push(1);
60
        $this->stack->push(2);
61
        $this->stack->push(3);
62
        $this->stack->push(5);
63
        $this->expectException(FullException::class);
64
        $this->stack->push(6);
65
    }
66
    
67 View Code Duplication
    public function testSize() {
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...
68
        $this->stack = new Stack();
69
        $this->assertEquals($this->stack->size(), 0);
70
        $this->stack->push(1);
71
        $this->assertEquals($this->stack->size(), 1);
72
        $this->stack->push(2);
73
        $this->assertEquals($this->stack->size(), 2);
74
        $this->stack->push(3);
75
        $this->assertEquals($this->stack->size(), 3);
76
        $this->stack->push(4);
77
        $this->assertEquals($this->stack->size(), 4);
78
        $this->stack->push(5);
79
        $this->assertEquals($this->stack->size(), 5);
80
    }
81
82 View Code Duplication
    public function testEmpty() {
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...
83
        $this->stack = new Stack();
84
        $this->assertTrue($this->stack->empty());
85
        $this->stack->push(true);
86
        $this->assertFalse($this->stack->empty());
87
        $this->stack->push("string");
88
        $this->stack->push(3.14);
89
        $this->stack->pop();
90
        $this->stack->pop();
91
        $this->stack->pop();
92
        $this->assertTrue($this->stack->empty());
93
    }
94
    
95 View Code Duplication
    public function testPeek() {
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...
96
        $this->stack = new Stack();
97
        $this->assertNull($this->stack->peek());
98
        $this->stack->push(1000);
99
        $this->assertEquals($this->stack->peek(), 1000);
100
        $this->stack->push(false);
101
        $this->assertEquals($this->stack->peek(), false);
102
        $this->stack->push(3.14);
103
        $this->assertEquals($this->stack->peek(), 3.14);
104
        $this->stack->push(4);
105
        $this->assertEquals($this->stack->pop(), 4);
106
        $this->assertEquals($this->stack->peek(), 3.14);
107
        $this->assertEquals($this->stack->pop(), 3.14);
108
        $this->assertEquals($this->stack->peek(), false);
109
        $this->assertEquals($this->stack->pop(), false);
110
        $this->assertEquals($this->stack->peek(), 1000);
111
        $this->assertEquals($this->stack->pop(), 1000);
112
        $this->assertNull($this->stack->peek());
113
    }
114
    
115 View Code Duplication
    public function testIsFull() {
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...
116
        $this->stack = new Stack();
117
        $this->assertFalse($this->stack->isFull());
118
        $this->stack->push(['hello']);
119
        $this->stack->push(false);
120
        $this->stack->push(['hello']);
121
        $this->stack->push(false);
122
        $this->stack->push(['hello']);
123
        $this->stack->push(false);
124
        $this->stack->push(['hello']);
125
        $this->stack->push(false);
126
        $this->assertFalse($this->stack->isFull());
127
    }
128
129
    public function testIsFullWithMaxSize() {
130
        $this->stack = new Stack(2);
131
        $this->stack->push(['hello']);
132
        $this->stack->push(false);
133
        $this->assertTrue($this->stack->isFull());
134
        $this->stack->pop();
135
        $this->assertFalse($this->stack->isFull());
136
    }
137
}