Skip to content

Commit

Permalink
Simplify the classical tests
Browse files Browse the repository at this point in the history
  • Loading branch information
programarivm committed Feb 20, 2025
1 parent 92cf9f7 commit e64576e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 128 deletions.
9 changes: 9 additions & 0 deletions tests/data/sample/classical.pgn
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,15 @@

1.exe4 exe5 *

[Event "-"]
[Site "-"]
[Date "-"]
[White "-"]
[Black "-"]
[Result "-"]

1.b4 h6 2.b5 a5 3.bxa6 h5 4.a7 h4 5.axb8 *

[Event "-"]
[Site "-"]
[Date "-"]
Expand Down
153 changes: 25 additions & 128 deletions tests/unit/Variant/Classical/BoardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public static function setUpBeforeClass(): void
public function sample_classical()
{
$expected = [
'total' => 80,
'valid' => 80,
'total' => 81,
'valid' => 81,
];

$parser = new PgnParser(new Move(), self::DATA_FOLDER . "/sample/" . "classical.pgn");
Expand Down Expand Up @@ -270,6 +270,29 @@ public function to_array_A59()
$this->assertSame($expected, $board->toArray());
}

/**
* @test
*/
public function sq_count_start()
{
$board = new Board();

$sqCount = $board->sqCount();

$expected = [
'a3', 'a4', 'a5', 'a6',
'b3', 'b4', 'b5', 'b6',
'c3', 'c4', 'c5', 'c6',
'd3', 'd4', 'd5', 'd6',
'e3', 'e4', 'e5', 'e6',
'f3', 'f4', 'f5', 'f6',
'g3', 'g4', 'g5', 'g6',
'h3', 'h4', 'h5', 'h6',
];

$this->assertEqualsCanonicalizing($expected, $sqCount['free']);
}

/**
* @test
*/
Expand Down Expand Up @@ -1286,28 +1309,6 @@ public function undo_e4_b6_Nf3_Bb7_Bc4_Nc6_Ke2()
$this->assertSame($expected, $board->toFen());
}

/**
* @test
*/
public function undo_e4_e5_Nf3_Nf6_Be2_Be7_O_O()
{
$board = new Board();

$board->play('w', 'e4');
$board->play('b', 'e5');
$board->play('w', 'Nf3');
$board->play('b', 'Nf6');
$board->play('w', 'Be2');
$board->play('b', 'Be7');
$board->play('w', 'O-O');

$board->undo();

$expected = 'rnbqk2r/ppppbppp/5n2/4p3/4P3/5N2/PPPPBPPP/RNBQK2R w KQkq -';

$this->assertSame($expected, $board->toFen());
}

/**
* @test
*/
Expand Down Expand Up @@ -1419,16 +1420,6 @@ public function play_lan_w_foo()
$board->playLan('w', 'foo');
}

/**
* @test
*/
public function play_lan_w_e2e4()
{
$board = new Board();

$this->assertTrue($board->playLan('w', 'e2e4'));
}

/**
* @test
*/
Expand Down Expand Up @@ -1475,17 +1466,6 @@ public function play_lan_e2e4_d7d5_a2a3_d5e4()
$this->assertTrue($board->playLan('b', 'd5e4'));
}

/**
* @test
*/
public function play_lan_e2e4_e7e5()
{
$board = new Board();

$this->assertTrue($board->playLan('w', 'e2e4'));
$this->assertFalse($board->playLan('w', 'e7e5'));
}

/**
* @test
*/
Expand All @@ -1511,19 +1491,6 @@ public function play_lan_d2d3_d7d6___b8d7_d2f3()
$this->assertTrue($board->playLan('w', 'b1d2'));
$this->assertTrue($board->playLan('b', 'b8d7'));
$this->assertTrue($board->playLan('w', 'd2f3'));

$expected = [
7 => [ 'r', '.', 'b', 'q', 'k', 'b', 'n', 'r' ],
6 => [ 'p', 'p', 'p', 'n', '.', 'p', 'p', 'p' ],
5 => [ '.', '.', '.', 'p', 'p', '.', '.', '.' ],
4 => [ '.', '.', '.', '.', '.', '.', '.', '.' ],
3 => [ '.', '.', '.', '.', '.', '.', '.', '.' ],
2 => [ '.', '.', '.', 'P', 'P', 'N', '.', '.' ],
1 => [ 'P', 'P', 'P', '.', '.', 'P', 'P', 'P' ],
0 => [ 'R', '.', 'B', 'Q', 'K', 'B', 'N', 'R' ],
];

$this->assertSame($expected, $board->toArray());
}

/**
Expand Down Expand Up @@ -1829,29 +1796,6 @@ public function c3_defends_b4_and_d4()
$this->assertEquals($expected, $board->pieceBySq("c3")->defendedSqs());
}

/**
* @test
*/
public function count_sq_start()
{
$board = new Board();

$sqCount = $board->sqCount();

$expected = [
'a3', 'a4', 'a5', 'a6',
'b3', 'b4', 'b5', 'b6',
'c3', 'c4', 'c5', 'c6',
'd3', 'd4', 'd5', 'd6',
'e3', 'e4', 'e5', 'e6',
'f3', 'f4', 'f5', 'f6',
'g3', 'g4', 'g5', 'g6',
'h3', 'h4', 'h5', 'h6',
];

$this->assertEqualsCanonicalizing($expected, $sqCount['free']);
}

/**
* @test
*/
Expand All @@ -1864,40 +1808,6 @@ public function play_lan_a4_b5_axb5_a6_b6()
$board->playLan('w', 'a4b5');
$board->playLan('b', 'a7a6');
$board->playLan('w', 'b5b6');

$expected = [
7 => [ 'r', 'n', 'b', 'q', 'k', 'b', 'n', 'r' ],
6 => [ '.', '.', 'p', 'p', 'p', 'p', 'p', 'p' ],
5 => [ 'p', 'P', '.', '.', '.', '.', '.', '.' ],
4 => [ '.', '.', '.', '.', '.', '.', '.', '.' ],
3 => [ '.', '.', '.', '.', '.', '.', '.', '.' ],
2 => [ '.', '.', '.', '.', '.', '.', '.', '.' ],
1 => [ '.', 'P', 'P', 'P', 'P', 'P', 'P', 'P' ],
0 => [ 'R', 'N', 'B', 'Q', 'K', 'B', 'N', 'R' ],
];

$this->assertSame($expected, $board->toArray());
}

/**
* @test
*/
public function b4_h6_b5_a5_bxa6_h5_a7_h4_axb8()
{
$board = (new SanPlay('1.b4 h6 2.b5 a5 3.bxa6 h5 4.a7 h4 5.axb8'))->validate()->board;

$expected = [
7 => [ 'r', 'Q', 'b', 'q', 'k', 'b', 'n', 'r' ],
6 => [ '.', 'p', 'p', 'p', 'p', 'p', 'p', '.' ],
5 => [ '.', '.', '.', '.', '.', '.', '.', '.' ],
4 => [ '.', '.', '.', '.', '.', '.', '.', '.' ],
3 => [ '.', '.', '.', '.', '.', '.', '.', 'p' ],
2 => [ '.', '.', '.', '.', '.', '.', '.', '.' ],
1 => [ 'P', '.', 'P', 'P', 'P', 'P', 'P', 'P' ],
0 => [ 'R', 'N', 'B', 'Q', 'K', 'B', 'N', 'R' ],
];

$this->assertSame($expected, $board->toArray());
}

/**
Expand All @@ -1916,19 +1826,6 @@ public function play_lan_b4_a6_b5_h6_h3_c5_g3_h5_b6()
$board->playLan('w', 'g2g3');
$board->playLan('b', 'h6h5');
$board->playLan('w', 'b5b6');

$expected = [
7 => [ 'r', 'n', 'b', 'q', 'k', 'b', 'n', 'r' ],
6 => [ '.', 'p', '.', 'p', 'p', 'p', 'p', '.' ],
5 => [ 'p', 'P', '.', '.', '.', '.', '.', '.' ],
4 => [ '.', '.', 'p', '.', '.', '.', '.', 'p' ],
3 => [ '.', '.', '.', '.', '.', '.', '.', '.' ],
2 => [ '.', '.', '.', '.', '.', '.', 'P', 'P' ],
1 => [ 'P', '.', 'P', 'P', 'P', 'P', '.', '.' ],
0 => [ 'R', 'N', 'B', 'Q', 'K', 'B', 'N', 'R' ],
];

$this->assertSame($expected, $board->toArray());
}

/**
Expand Down

0 comments on commit e64576e

Please sign in to comment.