1 | <?php |
||
2 | |||
3 | namespace App\Card; |
||
4 | |||
5 | use PHPUnit\Framework\TestCase; |
||
6 | |||
7 | /** |
||
8 | * Test cases for class Game21. |
||
9 | */ |
||
10 | class Game21Test extends TestCase |
||
11 | { |
||
12 | public function testCreateGame21(): void |
||
13 | { |
||
14 | $game = new Game21(); |
||
15 | // $this->assertInstanceOf("\App\Card\Game21", $game); |
||
16 | |||
17 | $res = $game->getTurn(); |
||
18 | $exp = "player"; |
||
19 | $this->assertEquals($exp, $res); |
||
20 | |||
21 | $res = $game->getWinner(); |
||
22 | $exp = null; |
||
23 | $this->assertEquals($exp, $res); |
||
24 | } |
||
25 | |||
26 | public function testPlayerAndBankDraw(): void |
||
27 | { |
||
28 | $game = new Game21(); |
||
29 | // $this->assertInstanceOf("\App\Card\Game21", $game); |
||
30 | |||
31 | $res = $game->playerDraw(); |
||
32 | $this->assertTrue($res >= 1 && $res <= 36); |
||
33 | |||
34 | $game->playerStop(); |
||
35 | $res = $game->getTurn(); |
||
36 | $exp = "bank"; |
||
37 | $this->assertEquals($exp, $res); |
||
38 | |||
39 | $res = $game->bankDraw(); |
||
40 | $this->assertTrue($res >= 1 && $res <= 36); |
||
41 | |||
42 | $res = $game->getWinner(); |
||
43 | $exp = null; |
||
44 | $this->assertEquals($exp, $res); |
||
45 | } |
||
46 | |||
47 | public function testBankDrawTooEarly(): void |
||
48 | { |
||
49 | $game = new Game21(); |
||
50 | $this->expectException(\Exception::class); |
||
51 | $this->expectExceptionMessage("Player has not stopped"); |
||
52 | $res = $game->bankDraw(); |
||
0 ignored issues
–
show
Unused Code
introduced
by
![]() |
|||
53 | |||
54 | } |
||
55 | |||
56 | public function testPlayerDrawTooLate(): void |
||
57 | { |
||
58 | $game = new Game21(); |
||
59 | $game->playerDraw(); |
||
60 | $game->playerStop(); |
||
61 | $this->expectException(\Exception::class); |
||
62 | $this->expectExceptionMessage("Player has stopped or game not started"); |
||
63 | $res = $game->playerDraw(); |
||
0 ignored issues
–
show
|
|||
64 | } |
||
65 | |||
66 | public function testGetPlayerAndBankHand(): void |
||
67 | { |
||
68 | $game = new Game21(); |
||
69 | $res = $game->playerDraw(); |
||
0 ignored issues
–
show
|
|||
70 | $hand = $game->getPlayerHand(); |
||
71 | |||
72 | $res = $game->getHandValue($hand); |
||
73 | $this->assertTrue($res >= 2 && $res <= 14); |
||
74 | |||
75 | $game->playerStop(); |
||
76 | $game->bankDraw(); |
||
77 | $hand = $game->getBankHand(); |
||
78 | $res = $game->getHandValue($hand); |
||
79 | $this->assertTrue($res >= 2 && $res <= 14); |
||
80 | |||
81 | } |
||
82 | public function testPlayerWinner(): void |
||
83 | { |
||
84 | $game = new Game21(); |
||
85 | for ($i = 0; $i < 10; $i++) { |
||
86 | $res = $game->playerDraw(); |
||
0 ignored issues
–
show
|
|||
87 | } |
||
88 | $res = $game->getWinner(); |
||
89 | $exp = "bank"; |
||
90 | $this->assertEquals($exp, $res); |
||
91 | } |
||
92 | public function testBankWinner(): void |
||
93 | { |
||
94 | $game = new Game21(); |
||
95 | $res = $game->playerDraw(); |
||
0 ignored issues
–
show
|
|||
96 | $game->playerStop(); |
||
97 | for ($i = 0; $i < 10; $i++) { |
||
98 | $game->bankDraw(); |
||
99 | } |
||
100 | $res = $game->getWinner(); |
||
101 | $exp = "player"; |
||
102 | $this->assertEquals($exp, $res); |
||
103 | } |
||
104 | } |
||
105 |