mirror of
https://github.com/TheRealOwenRees/chess-endgame-trainer.git
synced 2026-11-18 11:42:07 +00:00
Reject out-of-range endgame FENs at entry (#25)
Add FEN.piece_count/1 and reject positions with more than 7 pieces in the Endgame changeset, so an 8+ piece FEN fails at entry instead of saving and then blocking at play. Accumulate all FEN issues rather than letting a later check overwrite an earlier one, and guard the seed FENs with a test (dropping the out-of-range seed that bypassed the changeset).
This commit is contained in:
@@ -59,4 +59,27 @@ defmodule Chesstrainer.FENTest do
|
||||
assert FEN.normalize(fen) == fen
|
||||
end
|
||||
end
|
||||
|
||||
describe "piece_count/1" do
|
||||
test "counts kings and pieces, ignoring empty squares and slashes" do
|
||||
assert FEN.piece_count("8/8/3k4/8/8/3K1R2/8/8 w - - 0 1") == 3
|
||||
end
|
||||
|
||||
test "counts a full seven-piece position" do
|
||||
assert FEN.piece_count("6k1/5p2/6p1/8/7p/8/6PP/6K1 b - - 0 0") == 7
|
||||
end
|
||||
|
||||
test "counts a position beyond the tablebase range" do
|
||||
assert FEN.piece_count("3k4/2n2B2/1KP5/2B2p2/5b1p/7P/8/8 b - - 0 1") == 10
|
||||
end
|
||||
|
||||
test "counts a board field without clocks" do
|
||||
assert FEN.piece_count("8/8/3k4/8/8/3K1R2/8/8") == 3
|
||||
end
|
||||
|
||||
test "returns nil for a malformed board" do
|
||||
assert FEN.piece_count("not a fen") == nil
|
||||
assert FEN.piece_count(nil) == nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user