position-definition_test.rb 1.1 KB

123456789101112131415161718192021222324252627282930
  1. require 'chess-data'
  2. require 'minitest/autorun'
  3. describe ChessData::PositionDefinition do
  4. it "must correctly identify a simple 3P+2p ending" do
  5. defn = ChessData::PositionDefinition.new do
  6. exactly 3, "P"
  7. exactly 2, "p"
  8. end
  9. _(defn.check(ChessData::Board.from_fen("6k1/pp6/8/8/8/8/PPP5/4K3"))).must_equal true
  10. _(defn.check(ChessData::Board.from_fen("6k1/p7/8/7p/8/PP6/2P5/4K3"))).must_equal true
  11. _(defn.check(ChessData::Board.from_fen("6k1/pp6/b/8/8/Q/PPP5/4K3"))).must_equal false
  12. end
  13. it "must use at-least and at-most correctly" do
  14. defn = ChessData::PositionDefinition.new do
  15. at_most 4, "p"
  16. at_least 3, "P"
  17. at_most 1, "R"
  18. at_least 1, "n"
  19. end
  20. _(defn.check(ChessData::Board.from_fen("6k1/5n2/pp6/8/8/R7/KPPP4/8"))).must_equal true
  21. _(defn.check(ChessData::Board.from_fen("6k1/n4n2/pp6/8/8/R7/KPPPPPPP/8"))).must_equal true
  22. _(defn.check(ChessData::Board.from_fen("6k1/5n2/pp6/8/8/R6R/KPPP/8"))).must_equal false
  23. _(defn.check(ChessData::Board.from_fen("6k1/8/pp6/8/8/R7/KPPP4/8"))).must_equal false
  24. end
  25. end