Skip to content

Commit

Permalink
Merge pull request #16272 from lenguyenthanh/cleanup-event-test
Browse files Browse the repository at this point in the history
Clean up arbitraries for game.EventTest
  • Loading branch information
ornicar authored Oct 26, 2024
2 parents 9dba181 + 758a306 commit 18951c0
Showing 1 changed file with 3 additions and 27 deletions.
30 changes: 3 additions & 27 deletions modules/game/src/test/Arbitraries.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package lila.game

import chess.*
import chess.CoreArbitraries.given
import chess.CoreArbitraries.{ castleGen, given }
import org.scalacheck.{ Arbitrary, Gen }
import play.api.libs.json.JsObject
import chess.variant.Crazyhouse
Expand All @@ -12,21 +12,16 @@ object Arbitraries:
given [S, T](using SameRuntime[S, T], Arbitrary[S]): Arbitrary[T] = Arbitrary:
Arbitrary.arbitrary[S].map(summon[SameRuntime[S, T]].apply)

// TODO move Move.Castle to scalachess
given Arbitrary[Event.Castling] = Arbitrary:
for
color <- Arbitrary.arbitrary[Color]
king <- Gen.oneOf(color.backRank.squares)
kingTo <- Gen.oneOf(color.fold(List(Square.G1, Square.C1), List(Square.G8, Square.C8)))
rookTo <- Gen.oneOf(color.fold(List(Square.F1, Square.D1), List(Square.F8, Square.D8)))
rook <- Gen.oneOf(color.backRank.squares.filter(_ != king))
castle = Move.Castle(king, kingTo, rook, rookTo)
castle <- castleGen(color)
yield Event.Castling(castle, color)

given Arbitrary[Event.Enpassant] = Arbitrary:
for
color <- Arbitrary.arbitrary[Color]
pos <- Gen.oneOf(color.passablePawnRank.squares)
pos <- Gen.oneOf(color.passablePawnRank.bb.squares)
yield Event.Enpassant(pos, color)

// We use Event.Castling as a cookie for this test because We don't have an Arbitrary instance for JsObject yet
Expand All @@ -48,8 +43,6 @@ object Arbitraries:
blackOffersDraw <- Arbitrary.arbitrary[Boolean]
yield Event.State(turns, status, winner, whiteOffersDraw, blackOffersDraw)

given Arbitrary[PromotableRole] = Arbitrary(Gen.oneOf(Rook, Knight, Bishop, Queen))

given Arbitrary[Event.Promotion] = Arbitrary:
for
role <- Arbitrary.arbitrary[PromotableRole]
Expand All @@ -63,21 +56,6 @@ object Arbitraries:
nextLag <- Arbitrary.arbitrary[Option[Centis]]
yield Event.Clock(whiteTime, blackTime, nextLag)

given Arbitrary[Crazyhouse.Pocket] = Arbitrary:
for
pawn <- Gen.oneOf(0 to 8)
knight <- Gen.oneOf(0 to 2)
bishop <- Gen.oneOf(0 to 2)
rook <- Gen.oneOf(0 to 2)
queen <- Gen.oneOf(0 to 2)
yield Crazyhouse.Pocket(pawn, knight, bishop, rook, queen)

given Arbitrary[Crazyhouse.Data] = Arbitrary:
for
pockets <- Arbitrary.arbitrary[ByColor[Crazyhouse.Pocket]]
promoted <- Arbitrary.arbitrary[chess.bitboard.Bitboard]
yield Crazyhouse.Data(pockets, promoted)

given Arbitrary[Event.Move] = Arbitrary:
for
orig <- Arbitrary.arbitrary[Square]
Expand Down Expand Up @@ -110,5 +88,3 @@ object Arbitraries:
possibleDrops,
crazyData
)

extension (rank: Rank) def squares: List[Square] = Square.all.filter(_.rank == rank)

0 comments on commit 18951c0

Please sign in to comment.