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:
@@ -115,6 +115,30 @@ defmodule Chesstrainer.EndgamesTest do
|
||||
assert [msg] = errors_on(changeset).fen
|
||||
assert msg =~ "active color"
|
||||
end
|
||||
|
||||
test "rejects a FEN with more than 7 pieces" do
|
||||
attrs = %{
|
||||
fen: "3k4/2n2B2/1KP5/2B2p2/5b1p/7P/8/8 b - - 0 1",
|
||||
color: :black,
|
||||
result: :win,
|
||||
rating: 1500
|
||||
}
|
||||
|
||||
assert {:error, changeset} = Endgames.create_endgame(attrs)
|
||||
assert [msg] = errors_on(changeset).fen
|
||||
assert msg =~ "more than 7 pieces"
|
||||
end
|
||||
|
||||
test "accepts a FEN with exactly 7 pieces" do
|
||||
attrs = %{
|
||||
fen: "6k1/5p2/6p1/8/7p/8/6PP/6K1 b - - 0 1",
|
||||
color: :black,
|
||||
result: :win,
|
||||
rating: 1500
|
||||
}
|
||||
|
||||
assert {:ok, %Endgame{}} = Endgames.create_endgame(attrs)
|
||||
end
|
||||
end
|
||||
|
||||
describe "themes" do
|
||||
|
||||
Reference in New Issue
Block a user