forked from xx19941215/light-tips
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLinkedListTest.php
90 lines (71 loc) · 2.27 KB
/
LinkedListTest.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
<?php
namespace Test\DataStructure;
use DataStructure\LinkedList\LinkedList;
use \PHPUnit\Framework\TestCase;
class LinkedListTest extends TestCase
{
private $linkList;
public function setUp()
{
$this->linkList = new LinkedList();
parent::setUp();
}
public function testInsert()
{
$this->linkList->insert('xiao');
$this->assertEquals('xiao', $this->linkList->getNthNode(0)->data);
}
public function testInsertBefore()
{
$this->linkList->insert('xiao');
$this->linkList->insertBefore('work', 'xiao');
$this->assertEquals('work', $this->linkList->getNthNode(0)->data);
}
public function testInsertAfter()
{
$this->linkList->insert('xiao');
$this->linkList->insert('hello');
$this->linkList->insertAfter('work', 'hello');
$this->assertEquals('xiao', $this->linkList->getNthNode(0)->data);
}
public function testInsertAtFirst()
{
$this->linkList->insertAtFirst('xiao');
$this->assertEquals('xiao', $this->linkList->getNthNode(0)->data);
}
public function testSearch()
{
$this->linkList->insert('xiao');
$nodeList = $this->linkList->search('xiao');
$this->assertEquals('xiao', $nodeList->data);
}
public function testDeleteFirst()
{
$this->linkList->insert('xiao');
$this->linkList->insert('work');
$this->linkList->deleteFirst();
$this->assertEquals('work', $this->linkList->getNthNode(0)->data);
}
public function testDeleteLast()
{
$this->linkList->insert('foo');
$this->linkList->insert('bar');
$this->linkList->deleteLast();
$this->assertEquals('foo', $this->linkList->getNthNode(0)->data);
}
public function testDelete()
{
$this->linkList->insert('foo');
$this->linkList->insert('bar');
$this->linkList->delete('bar');
$this->assertEquals('foo', $this->linkList->getNthNode(0)->data);
}
public function testReverse()
{
$this->linkList->insert('foo');
$this->linkList->insert('bar');
$this->linkList->insert('xiao');
$this->linkList->reverse();
$this->assertEquals('xiao', $this->linkList->getNthNode(0)->data);
}
}