-
-
Notifications
You must be signed in to change notification settings - Fork 491
/
Copy pathStackTest.php
110 lines (93 loc) · 2.48 KB
/
StackTest.php
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
use PHPUnit\Framework\TestCase;
require_once __DIR__ . '/../../vendor/autoload.php';
require_once __DIR__ . '/../../DataStructures/Stack.php';
class StackTest extends TestCase
{
public function testConstruct()
{
$stack = new Stack([1, 2, 3]);
$this->assertEquals([1, 2, 3], $stack->toArray());
}
public function testDestruct()
{
$stack = new Stack([1, 2, 3]);
unset($stack);
$this->expectNotToPerformAssertions();
}
public function testPush()
{
$stack = new Stack();
$stack->push(1);
$stack->push(2);
$stack->push(3);
$this->assertEquals([1, 2, 3], $stack->toArray());
}
public function testPop()
{
$stack = new Stack([1, 2, 3]);
$this->assertEquals(3, $stack->pop());
$this->assertEquals([1, 2], $stack->toArray());
}
public function testPeek()
{
$stack = new Stack([1, 2, 3]);
$this->assertEquals(3, $stack->peek());
}
public function testIsEmpty()
{
$stack = new Stack();
$this->assertTrue($stack->isEmpty());
}
public function testPrint()
{
$stack = new Stack([1, 2, 3]);
$this->expectOutputString("1, 2, 3");
$stack->print();
}
public function testToString()
{
$stack = new Stack([1, 2, 3]);
$this->expectOutputString("1, 2, 3");
echo $stack;
}
public function testLength()
{
$stack = new Stack([1, 2, 3]);
$this->assertEquals(3, $stack->length());
}
public function testClear()
{
$stack = new Stack([1, 2, 3]);
$stack->clear();
$this->assertEquals([], $stack->toArray());
}
public function testSearch()
{
$stack = new Stack([1, 2, 3]);
$this->assertEquals(2, $stack->search(3));
}
public function testToArray()
{
$stack = new Stack([1, 2, 3]);
$this->assertEquals([1, 2, 3], $stack->toArray());
}
public function testFromArray()
{
$stack = new Stack();
$stack->fromArray([1, 2, 3]);
$this->assertEquals([1, 2, 3], $stack->toArray());
}
public function testReverse()
{
$stack = new Stack([1, 2, 3]);
$stack->reverse();
$this->assertEquals([3, 2, 1], $stack->toArray());
}
public function testSort()
{
$stack = new Stack([3, 2, 1]);
$stack->sort();
$this->assertEquals([1, 2, 3], $stack->toArray());
}
}