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:
@@ -0,0 +1,24 @@
|
||||
defmodule Chesstrainer.SeedsTest do
|
||||
use ExUnit.Case, async: true
|
||||
|
||||
alias Chesstrainer.FEN
|
||||
|
||||
Code.require_file("../../priv/repo/seeds/endgames.ex", __DIR__)
|
||||
|
||||
describe "seed endgames" do
|
||||
test "are normalised and within tablebase range" do
|
||||
for endgame <- Chesstrainer.Repo.Seeds.Endgames.all() do
|
||||
fen = FEN.normalize(endgame.fen)
|
||||
|
||||
assert length(String.split(fen, " ")) == 6,
|
||||
"seed FEN must have 6 fields: #{endgame.fen}"
|
||||
|
||||
refute String.ends_with?(fen, " 0"),
|
||||
"seed FEN keeps fullmove 0 after normalisation: #{endgame.fen}"
|
||||
|
||||
assert FEN.piece_count(fen) <= 7,
|
||||
"seed FEN has more than 7 pieces: #{endgame.fen}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user