/
MaterialEvalTest.php
88 lines (72 loc) · 2.11 KB
/
MaterialEvalTest.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
<?php
namespace Chess\Tests\Unit\Eval;
use Chess\Eval\MaterialEval;
use Chess\Play\SanPlay;
use Chess\Tests\AbstractUnitTestCase;
use Chess\Variant\Classical\Board;
class MaterialEvalTest extends AbstractUnitTestCase
{
/**
* @test
*/
public function starting_position()
{
$expected = [
'w' => 40.06,
'b' => 40.06,
];
$board = new Board();
$result = (new MaterialEval($board))->getResult();
$this->assertEquals($expected, $result);
}
/**
* @test
*/
public function A59()
{
$expectedResult = [
'w' => 35.73,
'b' => 34.73,
];
$expectedPhrase = [
"White has a slight material advantage.",
];
$A59 = file_get_contents(self::DATA_FOLDER.'/sample/A59.pgn');
$board = (new SanPlay($A59))->validate()->getBoard();
$materialEval = new MaterialEval($board);
$this->assertEqualsCanonicalizing($expectedResult, $materialEval->getResult());
$this->assertEqualsCanonicalizing($expectedPhrase, $materialEval->getExplanation());
}
/**
* @test
*/
public function C60()
{
$expected = [
'w' => 40.06,
'b' => 40.06,
];
$C60 = file_get_contents(self::DATA_FOLDER.'/sample/C60.pgn');
$board = (new SanPlay($C60))->validate()->getBoard();
$result = (new MaterialEval($board))->getResult();
$this->assertSame($expected, $result);
}
/**
* @test
*/
public function C00()
{
$expectedResult = [
'w' => 39.06,
'b' => 40.06,
];
$expectedPhrase = [
"Black has a slight material advantage.",
];
$C00 = file_get_contents(self::DATA_FOLDER.'/sample/C00.pgn');
$board = (new SanPlay($C00))->validate()->getBoard();
$materialEval = new MaterialEval($board);
$this->assertEqualsCanonicalizing($expectedResult, $materialEval->getResult());
$this->assertEqualsCanonicalizing($expectedPhrase, $materialEval->getExplanation());
}
}