|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Model; |
|
4
|
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Test cases for class BankPlayer. |
|
9
|
|
|
*/ |
|
10
|
|
|
class BankPlayerTest extends TestCase |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* Construct object and verify that the object is of the expected |
|
14
|
|
|
* type. |
|
15
|
|
|
*/ |
|
16
|
|
|
public function testCreateBankPlayerWithNoArguments(): void |
|
17
|
|
|
{ |
|
18
|
|
|
$player = new BankPlayer(); |
|
19
|
|
|
$this->assertInstanceOf("\App\Model\BankPlayer", $player); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Verify that the player's name is 'bank'. |
|
24
|
|
|
*/ |
|
25
|
|
|
|
|
26
|
|
|
public function testGetName(): void |
|
27
|
|
|
{ |
|
28
|
|
|
$player = new BankPlayer(); |
|
29
|
|
|
$res = $player->getName(); |
|
30
|
|
|
$exp = "bank"; |
|
31
|
|
|
$this->assertEquals($exp, $res); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Verify that the player's balance is 3000. |
|
36
|
|
|
*/ |
|
37
|
|
|
|
|
38
|
|
|
public function testGetBalance(): void |
|
39
|
|
|
{ |
|
40
|
|
|
$player = new BankPlayer(); |
|
41
|
|
|
$res = $player->getBalance(); |
|
42
|
|
|
$exp = 3000; |
|
43
|
|
|
$this->assertEquals($exp, $res); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Verify that the MakeMove-function returns hit as a first move. |
|
48
|
|
|
*/ |
|
49
|
|
|
|
|
50
|
|
|
public function testMakeMoveHit(): void |
|
51
|
|
|
{ |
|
52
|
|
|
$player = new BankPlayer(); |
|
53
|
|
|
$res = $player->makeMove(); |
|
54
|
|
|
$exp = "hit"; |
|
55
|
|
|
$this->assertEquals($exp, $res); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Verify that the MakeMove-function returns stand as a move when |
|
61
|
|
|
* hand value exceeds 17. |
|
62
|
|
|
*/ |
|
63
|
|
|
|
|
64
|
|
|
public function testMakeMoveStand(): void |
|
65
|
|
|
{ |
|
66
|
|
|
$player = new BankPlayer(); |
|
67
|
|
|
$player->addCardsToHand([new Card("hearts", "whatever", 11), new Card("hearts", "whatever", 7)]); |
|
68
|
|
|
$res = $player->makeMove(); |
|
69
|
|
|
$exp = "stand"; |
|
70
|
|
|
$this->assertEquals($exp, $res); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Verify previous bug, that the MakeMove-function returns stand as a move when |
|
76
|
|
|
* hand value is 22. |
|
77
|
|
|
*/ |
|
78
|
|
|
|
|
79
|
|
|
public function testMakeMoveStandFor22(): void |
|
80
|
|
|
{ |
|
81
|
|
|
$player = new BankPlayer(); |
|
82
|
|
|
$player->addCardsToHand([new Card("hearts", "whatever", 11), new Card("spade", "whatever", 11)]); |
|
83
|
|
|
|
|
84
|
|
|
$res = $player->makeMove(); |
|
85
|
|
|
$exp = "stand"; |
|
86
|
|
|
$this->assertEquals($exp, $res); |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|