-
-
Notifications
You must be signed in to change notification settings - Fork 501
/
Copy pathQueueTest.php
153 lines (128 loc) · 3.21 KB
/
QueueTest.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<?php
use PHPUnit\Framework\TestCase;
require_once __DIR__ . '/../../vendor/autoload.php';
require_once __DIR__ . "/../../DataStructures/Queue.php";
class QueueTest extends TestCase
{
/**
* @test
*/
public function shouldAddElementToQueue(): void
{
$queue = new Queue();
$queue->enqueue(1);
$queue->enqueue(2);
$queue->enqueue(3);
$this->assertEquals(3, $queue->size());
$this->assertEquals(1, $queue->peek());
}
/**
* @test
*/
public function shouldRemoveElementFromQueue(): void
{
$queue = new Queue();
$queue->enqueue(1);
$queue->enqueue(2);
$queue->enqueue(3);
$this->assertEquals(1, $queue->dequeue());
$this->assertEquals(2, $queue->peek());
$this->assertEquals(2, $queue->size());
}
/**
* @test
*/
public function shouldReturnCorrectValueWhenDequeue(): void
{
$queue = new Queue();
$queue->enqueue(1);
$queue->enqueue(2);
$queue->enqueue(3);
$this->assertEquals(1, $queue->dequeue());
$this->assertEquals(2, $queue->dequeue());
$this->assertEquals(3, $queue->dequeue());
}
/**
* @test
*/
public function shouldReturnNullWhenDequeueEmptyQueue(): void
{
$queue = new Queue();
$this->assertNull($queue->dequeue());
}
/**
* @test
*/
public function shouldReturnTrueIfQueueIsEmpty(): void
{
$queue = new Queue();
$this->assertTrue($queue->isEmpty());
}
/**
* @test
*/
public function shouldReturnFalseIfQueueIsNotEmpty(): void
{
$queue = new Queue();
$queue->enqueue(1);
$this->assertFalse($queue->isEmpty());
}
/**
* @test
*/
public function shouldReturnQueueSize(): void
{
$queue = new Queue();
$queue->enqueue(1);
$queue->enqueue(2);
$queue->enqueue(3);
$this->assertEquals(3, $queue->size());
$this->assertEquals(1, $queue->peek());
}
/**
* @test
*/
public function shouldReturnFrontElement(): void
{
$queue = new Queue();
$queue->enqueue(1);
$queue->enqueue(2);
$queue->enqueue(3);
$this->assertEquals(1, $queue->peek());
$this->assertEquals(3, $queue->size());
}
/**
* @test
*/
public function shouldReturnNullWhenPeekEmptyQueue(): void
{
$queue = new Queue();
$this->assertNull($queue->peek());
}
/**
* @test
*/
public function shouldClearQueue(): void
{
$queue = new Queue();
$queue->enqueue(1);
$queue->enqueue(2);
$queue->enqueue(3);
$queue->clear();
$this->assertTrue($queue->isEmpty());
$this->assertEquals(0, $queue->size());
$this->assertNull($queue->peek());
}
/**
* @test
*/
public function shouldReturnStringRepresentation(): void
{
$queue = new Queue();
$queue->enqueue(1);
$queue->enqueue(2);
$queue->enqueue(3);
$this->assertIsString($queue->toString());
$this->assertEquals("1, 2, 3", $queue->toString(', '));
}
}