Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump scala chess 16.3.3 and Improve test with literal uci #366

Merged
merged 2 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions app/src/main/scala/model.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ object GameId:
extension (id: GameId) def value: String = id

object ChessCirceCodecs:
given Encoder[Fen.Epd] = encodeString.contramap(_.value)
given Decoder[Fen.Epd] = decodeString.map(Fen.Epd.apply)
given Encoder[Variant] = encodeString.contramap(_.name)
given Encoder[Fen.Full] = encodeString.contramap(_.value)
given Decoder[Fen.Full] = decodeString.map(Fen.Full.apply)
given Encoder[Variant] = encodeString.contramap(_.name)
given Decoder[Variant] =
decodeString.emap: s =>
Variant.byName(s).toRight(s"Invalid variant: $s")
Expand All @@ -59,7 +59,7 @@ object Fishnet:
case class WorkResponse(
work: Work,
game_id: GameId,
position: Fen.Epd,
position: Fen.Full,
moves: String,
variant: Variant
) derives Encoder.AsObject
Expand All @@ -74,7 +74,7 @@ object Lila:

case class Request(
id: GameId,
initialFen: Fen.Epd,
initialFen: Fen.Full,
variant: Variant,
moves: String,
level: Int,
Expand All @@ -100,8 +100,8 @@ object Lila:
)
case _ => None

def readFen(str: String): Option[Fen.Epd] =
Option.when(str.nonEmpty)(Fen.Epd(str))
def readFen(str: String): Option[Fen.Full] =
Option.when(str.nonEmpty)(Fen.Full(str))

def readClock(s: String): Option[Clock] =
s.split(" ", 3) match
Expand Down
4 changes: 2 additions & 2 deletions app/src/test/scala/Arbitraries.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package lila.fishnet

import chess.CoreArbitraries.given
import chess.format.Fen.Epd
import chess.format.Fen.Full
import org.scalacheck.Arbitrary.*
import org.scalacheck.{ Arbitrary, Cogen, Gen }

Expand Down Expand Up @@ -34,7 +34,7 @@ object Arbitraries:
level <- Gen.choose(1, 8)
clock <- arbitrary[Option[Lila.Clock]]
variant <- arbitrary[chess.variant.Variant]
yield Lila.Request(id, Epd.initial, variant, moves, level, clock)
yield Lila.Request(id, Full.initial, variant, moves, level, clock)

given Arbitrary[Work.Task] = Arbitrary:
for
Expand Down
7 changes: 4 additions & 3 deletions app/src/test/scala/ExecutorTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package lila.fishnet
import cats.effect.{ IO, Ref }
import cats.syntax.all.*
import chess.format.Uci
import chess.macros.uci
import org.typelevel.log4cats.Logger
import org.typelevel.log4cats.noop.NoOpLogger
import weaver.*
Expand All @@ -27,7 +28,7 @@ object ExecutorTest extends SimpleIOSuite:
val key = ClientKey("key")
val key2 = ClientKey("key2")

val validMove = BestMove(Uci("e2e4").get)
val validMove = BestMove(uci"e2e4")

test("acquire when there is no work should return none"):
for
Expand Down Expand Up @@ -68,7 +69,7 @@ object ExecutorTest extends SimpleIOSuite:
acquired <- executor.acquire(key)
_ <- executor.move(acquired.get.id, key, validMove.some)
response <- ref.get.map(_.head)
yield expect.same(response, Lila.Response(request.id, request.moves, Uci.Move("e2e4").get))
yield expect.same(response, Lila.Response(request.id, request.moves, uci"e2e4"))

test("post move after timeout should not send move"):
for
Expand All @@ -91,7 +92,7 @@ object ExecutorTest extends SimpleIOSuite:
acquired <- executor.acquire(key)
_ <- executor.move(acquired.get.id, key, validMove.some)
response <- ref.get.map(_.head)
yield expect.same(response, Lila.Response(request.id, request.moves, Uci.Move("e2e4").get))
yield expect.same(response, Lila.Response(request.id, request.moves, uci"e2e4"))

test("post null move should remove the task"):
for
Expand Down
3 changes: 2 additions & 1 deletion app/src/test/scala/IntegrationTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package lila.fishnet
import cats.effect.{ IO, Ref, Resource }
import cats.syntax.all.*
import chess.format.Uci
import chess.macros.uci
import com.comcast.ip4s.*
import com.dimafeng.testcontainers.GenericContainer
import io.chrisdavenport.rediculous.RedisPubSub
Expand Down Expand Up @@ -54,7 +55,7 @@ object IntegrationTest extends IOSuite:
test("let's play a game"): res =>
val fishnet = Fishnet("2.7.2", ClientKey("secret-key"))
val fishnetAcquireRequest = Acquire(fishnet)
val bestMoves = List("e7e6", "d7d5", "d8d6").traverse(Uci.apply).get
val bestMoves = List(uci"e7e6", uci"d7d5", uci"d8d6")
val postMoves = bestMoves.map(m => PostMove(fishnet, Move(BestMove(m).some)))

val gameId = "CPzkP0tq"
Expand Down
2 changes: 1 addition & 1 deletion app/src/test/scala/http/FishnetRoutesTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ object FishnetRoutesTest extends SimpleIOSuite:
id = WorkId("workid"),
request = Lila.Request(
id = GameId("gameid"),
initialFen = chess.format.Fen.Epd("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR"),
initialFen = chess.format.Fen.Full("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR"),
moves = "",
variant = chess.variant.Standard,
level = 1,
Expand Down
2 changes: 1 addition & 1 deletion project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ object Dependencies {
val ciris = "3.6.0"
val kamon = "2.5.11"
val kamonAgent = "1.0.18"
val chess = "15.7.11"
val chess = "16.3.3"
val catsEffect = "3.5.5"
}

Expand Down