mirror of
https://gitlab.com/manzerbredes/chess-move-interface.git
synced 2025-06-06 14:37:40 +00:00
- Debug parser (carriage returns)
- Improve test framework
This commit is contained in:
parent
bb914f047b
commit
f4f436870f
11 changed files with 1577 additions and 32 deletions
|
@ -1,8 +1,20 @@
|
|||
include_directories(./catch3/)
|
||||
|
||||
# Copy asset files
|
||||
file(COPY pgn_files DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/)
|
||||
|
||||
# Run tests
|
||||
add_executable(pgnp_tests tests.cpp ./catch3/catch_amalgamated.cpp)
|
||||
target_link_libraries(pgnp_tests pgnp)
|
||||
# Configure catch3
|
||||
include_directories(./catch3/)
|
||||
add_library(catch3 SHARED ./catch3/catch_amalgamated.cpp)
|
||||
|
||||
# Add tests
|
||||
add_executable(pgnp_valid valid.cpp)
|
||||
target_link_libraries(pgnp_valid pgnp catch3)
|
||||
add_test(PGNP_Valid_PGN_Set pgnp_valid)
|
||||
|
||||
add_executable(pgnp_str str.cpp)
|
||||
target_link_libraries(pgnp_str pgnp catch3)
|
||||
add_test(PGNP_STR_Compliant_Set pgnp_str)
|
||||
|
||||
add_executable(pgnp_combined combined.cpp)
|
||||
target_link_libraries(pgnp_combined pgnp catch3)
|
||||
add_test(PGNP_Combined_Set pgnp_combined)
|
43
tests/combined.cpp
Normal file
43
tests/combined.cpp
Normal file
|
@ -0,0 +1,43 @@
|
|||
#include "pgnp.hpp"
|
||||
#include <catch_amalgamated.hpp>
|
||||
|
||||
using namespace pgnp;
|
||||
|
||||
TEST_CASE("Hartwig PGN", "[combined/hartwig]") {
|
||||
// PGN source: https://www.angelfire.com/games3/smartbridge/
|
||||
|
||||
pgnp::PGN pgn;
|
||||
pgn.FromFile("pgn_files/combined/hartwig.pgn");
|
||||
|
||||
// Count games
|
||||
REQUIRE_NOTHROW([&]() {
|
||||
char i = 0;
|
||||
try {
|
||||
while (true) {
|
||||
pgn.ParseNextGame();
|
||||
i++;
|
||||
}
|
||||
} catch (const NoGameFound &e) {
|
||||
CHECK(i == 29);
|
||||
}
|
||||
}());
|
||||
|
||||
SECTION("Check comments of a game") {
|
||||
pgnp::PGN pgn;
|
||||
pgn.FromFile("pgn_files/combined/hartwig.pgn");
|
||||
pgn.ParseNextGame();
|
||||
pgn.ParseNextGame();
|
||||
pgn.ParseNextGame();
|
||||
pgn.ParseNextGame();
|
||||
pgn.ParseNextGame(); // Load game 5
|
||||
|
||||
HalfMove *m = new HalfMove();
|
||||
pgn.GetMoves(m);
|
||||
std::cout << m->comment;
|
||||
CHECK(m->comment ==
|
||||
"I had actually prepared 1.d4 for the tournament, but I backed out "
|
||||
"in every (!) game for various different reasons. In this case it "
|
||||
"was because things were in such a rut I would only be cheered by "
|
||||
"winning in crushing style. Thankfully it worked!");
|
||||
}
|
||||
}
|
1478
tests/pgn_files/combined/hartwig.pgn
Normal file
1478
tests/pgn_files/combined/hartwig.pgn
Normal file
File diff suppressed because it is too large
Load diff
17
tests/str.cpp
Normal file
17
tests/str.cpp
Normal file
|
@ -0,0 +1,17 @@
|
|||
#include "pgnp.hpp"
|
||||
#include <catch_amalgamated.hpp>
|
||||
|
||||
using namespace pgnp;
|
||||
|
||||
TEST_CASE("Seven Tag Roster", "[std/pgn1]") {
|
||||
PGN pgn;
|
||||
REQUIRE_NOTHROW(pgn.FromFile("pgn_files/str/pgn1.pgn"));
|
||||
REQUIRE_NOTHROW(pgn.ParseNextGame());
|
||||
|
||||
REQUIRE_NOTHROW(pgn.STRCheck());
|
||||
HalfMove *m = new HalfMove();
|
||||
pgn.GetMoves(m);
|
||||
REQUIRE(m->GetLength() == 85);
|
||||
CHECK(pgn.GetResult() == "1/2-1/2");
|
||||
REQUIRE_THROWS_AS(pgn.ParseNextGame(),NoGameFound);
|
||||
}
|
|
@ -87,16 +87,3 @@ TEST_CASE("Valid PGN", "[valid/pgn2]") {
|
|||
}
|
||||
REQUIRE_THROWS_AS(pgn.ParseNextGame(),NoGameFound);
|
||||
}
|
||||
|
||||
TEST_CASE("Seven Tag Roster", "[std/pgn1]") {
|
||||
PGN pgn;
|
||||
REQUIRE_NOTHROW(pgn.FromFile("pgn_files/str/pgn1.pgn"));
|
||||
REQUIRE_NOTHROW(pgn.ParseNextGame());
|
||||
|
||||
REQUIRE_NOTHROW(pgn.STRCheck());
|
||||
HalfMove *m = new HalfMove();
|
||||
pgn.GetMoves(m);
|
||||
REQUIRE(m->GetLength() == 85);
|
||||
CHECK(pgn.GetResult() == "1/2-1/2");
|
||||
REQUIRE_THROWS_AS(pgn.ParseNextGame(),NoGameFound);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue