Skip to content

Commit

Permalink
remove specs2, all tests are now on munit
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Oct 19, 2023
1 parent aab97a1 commit 924bcac
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 72 deletions.
8 changes: 4 additions & 4 deletions bench/src/main/scala/benchmarks/HashBench.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,29 @@ class HashBench:

@Setup
def setup() =
var results = for
val results = for
results <- Fixtures.gamesForPerfTest.traverse(Reader.full(_))
replays <- results.traverse(_.valid)
yield replays.flatMap(_.moves).map(_.situationAfter)
situations = results.toOption.get

@Benchmark
def hashes(bh: Blackhole) =
var result = situations.map: x =>
val result = situations.map: x =>
Blackhole.consumeCPU(Work)
Hash(x)
bh.consume(result)

@Benchmark
def repetition5(bh: Blackhole) =
var result = situations.map: x =>
val result = situations.map: x =>
Blackhole.consumeCPU(Work)
x.board.history.fivefoldRepetition
bh.consume(result)

@Benchmark
def repetition3(bh: Blackhole) =
var result = situations.map: x =>
val result = situations.map: x =>
Blackhole.consumeCPU(Work)
x.board.history.threefoldRepetition
bh.consume(result)
2 changes: 1 addition & 1 deletion bench/src/main/scala/benchmarks/PerftBench.scala
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class PerftBench:
perfts.take(games).map(_.withLimit(nodes))

private def bench(perfts: List[Perft], variant: Variant)(bh: Blackhole) =
var x = perfts.map:
val x = perfts.map:
Blackhole.consumeCPU(Work)
_.calculate(variant)
bh.consume(x)
Expand Down
4 changes: 2 additions & 2 deletions bench/src/main/scala/benchmarks/PgnBench.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ class PgnBench:

@Benchmark
def pgnParser(bh: Blackhole) =
var result = pgnStrs.map: x =>
val result = pgnStrs.map: x =>
Blackhole.consumeCPU(Work)
Parser.full(x)
bh.consume(result)
result

@Benchmark
def pgnRender(bh: Blackhole) =
var result = pgns.map: x =>
val result = pgns.map: x =>
Blackhole.consumeCPU(Work)
x.render
bh.consume(result)
Expand Down
2 changes: 0 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ lazy val testKit = project
name := "scalachess-test-kit",
libraryDependencies ++= List(
"org.scalacheck" %% "scalacheck" % "1.17.0",
"org.specs2" %% "specs2-core" % "4.20.2" % Test,
"org.specs2" %% "specs2-cats" % "4.20.2" % Test,
"org.scalameta" %% "munit" % "1.0.0-M8" % Test,
"org.scalameta" %% "munit-scalacheck" % "1.0.0-M8" % Test,
"com.disneystreaming" %% "weaver-cats" % "0.8.3" % Test,
Expand Down
36 changes: 3 additions & 33 deletions test-kit/src/test/scala/ChessTest.scala
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
package chess

import cats.syntax.all.*
import org.specs2.matcher.{ EitherMatchers, Matcher }
import org.specs2.mutable.Specification
import scala.language.implicitConversions

import chess.format.{ EpdFen, Fen, Visual }
import chess.format.pgn.PgnStr
import chess.variant.Variant
import format.{ EpdFen, Fen, Uci, Visual }
import format.pgn.PgnStr
import variant.{ Chess960, Variant }
import bitboard.Board as BBoard
import chess.format.Uci
import chess.variant.Chess960

trait ChessTestCommon:

Expand Down Expand Up @@ -174,28 +169,3 @@ trait ChessTest extends munit.FunSuite with ChessTestCommon with MunitExtensions

def assertGame(game: Game, visual: String)(using Location) =
assertEquals(game.board.visual, (Visual << visual).visual)

trait ChessSpecs extends Specification with EitherMatchers with ChessTestCommon:

def fenToGame(positionString: EpdFen, variant: Variant): Either[String, Game] =
fenToGameEither(positionString, variant)

def bePoss(poss: Square*) = // : Matcher[Option[Iterable[square]]] =
beSome: (p: Iterable[Square]) =>
sortPoss(p.toList).map(_.key) must_== sortPoss(poss.toList).map(_.key)

def bePoss(board: Board, visual: String) = // : Matcher[Option[Iterable[square]]] =
beSome: (p: Iterable[Square]) =>
Visual.addNewLines(Visual.>>|(board, Map(p -> 'x'))) must_== visual

def beBoard(visual: String): Matcher[Either[ErrorStr, Board]] =
beRight.like:
_.visual must_== (Visual << visual).visual

def beSituation(visual: String): Matcher[Either[ErrorStr, Situation]] =
beRight.like:
_.board.visual must_== (Visual << visual).visual

def beGame(visual: String): Matcher[Either[ErrorStr, Game]] =
beRight.like:
_.board.visual must_== (Visual << visual).visual
57 changes: 27 additions & 30 deletions test-kit/src/test/scala/perft/PerftTest.scala
Original file line number Diff line number Diff line change
@@ -1,30 +1,27 @@
// package chess
// package perft
//
// import org.specs2.specification.core.Fragments
//
// import chess.variant.*
//
// class PerftTest extends ChessTest:
//
// private def genTests(name: String, tests: List[Perft], variant: Variant, nodeLimit: Long): Fragments =
// name should:
// Fragments.foreach(tests) { perft =>
// perft.id in:
// val result = perft.withLimit(nodeLimit).calculate(variant)
// Fragments.foreach(result) { r =>
// s"${r.depth}" in { r.result must_== r.expected }
// }
// }
//
// val nodeLimits = 1_000_000L
// genTests("calculate ThreeCheck perfts", Perft.threeCheckPerfts, ThreeCheck, nodeLimits)
// genTests("calculate Antichess perfts", Perft.antichessPerfts, Antichess, nodeLimits)
// genTests("calculate Atomic perfts", Perft.atomicPerfts, Atomic, nodeLimits)
// genTests("calculate Crazyhouse perfts", Perft.crazyhousePerfts, Crazyhouse, nodeLimits)
// genTests("calculate Horde perfts", Perft.hordePerfts, Horde, nodeLimits)
// genTests("calculate RacingKings perfts", Perft.racingkingsPerfts, RacingKings, nodeLimits)
// // for the shake of time we only test the first 50 cases in random.peft, run FullRandomPerftTest.scala for all cases
// genTests("calculate random perfts", Perft.randomPerfts.take(100), Chess960, nodeLimits)
// genTests("calculate tricky perfts", Perft.trickyPerfts, Chess960, nodeLimits)
// genTests("calculate chess960 perfts", Perft.chess960, Chess960, nodeLimits)
package chess
package perft

import chess.variant.*

class PerftTest extends ChessTest:

private def genTests(name: String, tests: List[Perft], variant: Variant, nodeLimit: Long)(using
munit.Location
) =
tests.foreach: perft =>
val result = perft.withLimit(nodeLimit).calculate(variant)
result.foreach: r =>
test(s"$name ${perft.id} depth: ${r.depth}"):
assertEquals(r.result, r.expected)

val nodeLimits = 1_000_000L
genTests("calculate ThreeCheck perfts", Perft.threeCheckPerfts, ThreeCheck, nodeLimits)
genTests("calculate Antichess perfts", Perft.antichessPerfts, Antichess, nodeLimits)
genTests("calculate Atomic perfts", Perft.atomicPerfts, Atomic, nodeLimits)
genTests("calculate Crazyhouse perfts", Perft.crazyhousePerfts, Crazyhouse, nodeLimits)
genTests("calculate Horde perfts", Perft.hordePerfts, Horde, nodeLimits)
genTests("calculate RacingKings perfts", Perft.racingkingsPerfts, RacingKings, nodeLimits)
// for the shake of time we only test the first 50 cases in random.peft, run FullRandomPerftTest.scala for all cases
genTests("calculate random perfts", Perft.randomPerfts.take(100), Chess960, nodeLimits)
genTests("calculate tricky perfts", Perft.trickyPerfts, Chess960, nodeLimits)
genTests("calculate chess960 perfts", Perft.chess960, Chess960, nodeLimits)

0 comments on commit 924bcac

Please sign in to comment.