-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCommandTest.php
More file actions
94 lines (75 loc) · 2.71 KB
/
CommandTest.php
File metadata and controls
94 lines (75 loc) · 2.71 KB
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
<?php
namespace DesignPatterns\Structural\Bridge\Test;
use DesignPatterns\Behavioral\Command\Command\BottomCommand;
use DesignPatterns\Behavioral\Command\Command\LeftCommand;
use DesignPatterns\Behavioral\Command\Command\RightCommand;
use DesignPatterns\Behavioral\Command\Command\TopCommand;
use DesignPatterns\Behavioral\Command\Field;
use DesignPatterns\Behavioral\Command\Joystick;
use DesignPatterns\Behavioral\Command\Point;
/**
* @author Vlad Riabchenko <contact@vria.eu>
*/
class CommandTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Joystick
*/
private $joystick;
/**
* @var Field
*/
private $field;
protected function setUp()
{
$this->field = new Field(new Point(1, 1), new Point(2, 2));
$this->joystick = new Joystick();
$this->joystick->addKey('left', new LeftCommand($this->field));
$this->joystick->addKey('right', new RightCommand($this->field));
$this->joystick->addKey('top', new TopCommand($this->field));
$this->joystick->addKey('bottom', new BottomCommand($this->field));
}
public function testLeft()
{
$this->joystick->pressKey('left');
$this->assertEquals(new Point(0, 1), $this->field->getPlayer());
}
public function testRight()
{
$this->joystick->pressKey('right');
$this->assertEquals(new Point(2, 1), $this->field->getPlayer());
}
public function testTop()
{
$this->joystick->pressKey('top');
$this->assertEquals(new Point(1, 0), $this->field->getPlayer());
}
public function testBottom()
{
$this->joystick->pressKey('bottom');
$this->assertEquals(new Point(1, 2), $this->field->getPlayer());
}
public function testUndo()
{
$this->joystick->pressKey('bottom');
$this->assertEquals(new Point(1, 2), $this->field->getPlayer());
$this->joystick->undo();
$this->assertEquals(new Point(1, 1), $this->field->getPlayer());
}
public function testReachGoal()
{
$this->assertFalse($this->field->checkGoal());
$this->joystick->pressKey('bottom'); // 1, 2
$this->assertFalse($this->field->checkGoal());
$this->joystick->pressKey('bottom'); // 1, 3
$this->assertFalse($this->field->checkGoal());
$this->joystick->pressKey('right'); // 2, 3
$this->assertFalse($this->field->checkGoal());
$this->joystick->pressKey('right'); // 3, 3
$this->assertFalse($this->field->checkGoal());
$this->joystick->pressKey('top'); // 3, 2
$this->assertFalse($this->field->checkGoal());
$this->joystick->pressKey('left'); // 2, 2
$this->assertTrue($this->field->checkGoal());
}
}