Skip to content

Commit

Permalink
different traits for specs2/munit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Oct 15, 2023
1 parent 99202e9 commit 8975550
Show file tree
Hide file tree
Showing 48 changed files with 75 additions and 78 deletions.
2 changes: 1 addition & 1 deletion test-kit/src/test/scala/AntichessVariantTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import chess.format.{ EpdFen, Fen }
import chess.format.pgn.Reader
import chess.variant.Antichess

class AntichessVariantTest extends ChessTest:
class AntichessVariantTest extends ChessSpecs:

// Random PGN taken from FICS
val fullGame =
Expand Down
2 changes: 1 addition & 1 deletion test-kit/src/test/scala/AtomicVariantTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import chess.variant.Atomic
import chess.format.EpdFen
import chess.format.pgn.SanStr

class AtomicVariantTest extends ChessTest:
class AtomicVariantTest extends ChessSpecs:

"Atomic chess" should:

Expand Down
2 changes: 1 addition & 1 deletion test-kit/src/test/scala/AutodrawTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Square.*
import variant.Standard
import chess.format.EpdFen

class AutodrawTest extends ChessTest:
class AutodrawTest extends ChessSpecs:

"detect automatic draw" should:
"by lack of pieces" in:
Expand Down
2 changes: 1 addition & 1 deletion test-kit/src/test/scala/BerserkTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package chess

import scala.language.implicitConversions

class BerserkTest extends ChessTest:
class BerserkTest extends ChessSpecs:

def whiteBerserk(minutes: Int, seconds: Int) =
Clock(minutes * 60, seconds).goBerserk(White).remainingTime(White).centis * .01
Expand Down
2 changes: 1 addition & 1 deletion test-kit/src/test/scala/BishopTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package chess
import scala.language.implicitConversions
import Square.*

class BishopTest extends ChessTest:
class BishopTest extends ChessSpecs:

"a bishop" should:

Expand Down
2 changes: 1 addition & 1 deletion test-kit/src/test/scala/BoardTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package chess
import scala.language.implicitConversions
import Square.*

class BoardTest extends ChessTest:
class BoardTest extends ChessSpecs:

val board = makeBoard

Expand Down
2 changes: 1 addition & 1 deletion test-kit/src/test/scala/CastlingTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import variant.FromPosition
import variant.Chess960
import format.EpdFen

class CastlingTest extends ChessTest:
class CastlingTest extends ChessSpecs:

"king side" should:
val goodHist = """
Expand Down
2 changes: 1 addition & 1 deletion test-kit/src/test/scala/Chess960Test.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import variant.Chess960
import chess.format.pgn.Reader
import chess.format.EpdFen

class Chess960Test extends ChessTest:
class Chess960Test extends ChessSpecs:

"Chess960 chess" should:

Expand Down
55 changes: 28 additions & 27 deletions test-kit/src/test/scala/ChessTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import bitboard.Board as BBoard
import chess.format.Uci
import chess.variant.Chess960

trait ChessTest extends Specification with EitherMatchers:
trait ChessTestCommon:

given Conversion[String, Board] = Visual.<<
given Conversion[String, PgnStr] = PgnStr(_)
Expand Down Expand Up @@ -78,37 +78,12 @@ trait ChessTest extends Specification with EitherMatchers:

def makeEmptyBoard: Board = Board(BBoard.empty, chess.variant.Standard)

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

def makeGame: Game = Game(makeBoard, White)

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 { case b =>
b.visual must_== (Visual << visual).visual
}

def beSituation(visual: String): Matcher[Either[ErrorStr, Situation]] =
beRight.like { case s =>
s.board.visual must_== (Visual << visual).visual
}

def beGame(visual: String): Matcher[Either[ErrorStr, Game]] =
beRight.like { case g =>
g.board.visual must_== (Visual << visual).visual
}

def sortPoss(poss: Seq[Square]): Seq[Square] = poss.sortBy(_.key)

def pieceMoves(piece: Piece, square: Square): Option[List[Square]] =
(makeEmptyBoard place (piece, square)) map { b =>
makeEmptyBoard.place(piece, square).map { b =>
Situation(b, piece.color).movesAt(square).map(_.dest)
}

Expand All @@ -127,3 +102,29 @@ trait ChessTest extends Specification with EitherMatchers:
unmovedRooks = unmovedRooks,
halfMoveClock = halfMoveClock
)

trait ChessTest extends munit.FunSuite with ChessTestCommon:

end ChessTest

trait ChessSpecs extends Specification with EitherMatchers with ChessTestCommon:

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
2 changes: 1 addition & 1 deletion test-kit/src/test/scala/ClockTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package chess
import scala.language.implicitConversions
import Square.*

class ClockTest extends ChessTest:
class ClockTest extends ChessSpecs:

given Conversion[Int, Clock.LimitSeconds] = Clock.LimitSeconds(_)
given Conversion[Int, Clock.IncrementSeconds] = Clock.IncrementSeconds(_)
Expand Down
2 changes: 1 addition & 1 deletion test-kit/src/test/scala/ColorTest.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package chess

class ColorTest extends munit.FunSuite:
class ColorTest extends ChessTest:

test("unary !"):
assertEquals(!White, Black)
Expand Down
2 changes: 1 addition & 1 deletion test-kit/src/test/scala/CrazyhouseVariantTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import chess.format.pgn.SanStr
import chess.Square.*
import chess.bitboard.Bitboard

class CrazyhouseVariantTest extends ChessTest:
class CrazyhouseVariantTest extends ChessSpecs:

"Crazyhouse" should:

Expand Down
2 changes: 1 addition & 1 deletion test-kit/src/test/scala/DividerTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package chess
import scala.language.implicitConversions
import MoveOrDrop.*

class DividerTest extends ChessTest:
class DividerTest extends ChessSpecs:

def makeReplay(moves: String) =
format.pgn.Reader.full(moves).toOption.get match
Expand Down
2 changes: 1 addition & 1 deletion test-kit/src/test/scala/GameTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package chess
import scala.language.implicitConversions
import Square.*

class GameTest extends ChessTest:
class GameTest extends ChessSpecs:

"prevent castle by capturing a rook" should:
val game = Game(
Expand Down
2 changes: 1 addition & 1 deletion test-kit/src/test/scala/HashTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import variant.{ Antichess, Atomic, Crazyhouse, Standard, ThreeCheck }
import chess.format.{ EpdFen, Fen, Uci }
import chess.format.pgn.SanStr

class HashTest extends ChessTest:
class HashTest extends ChessSpecs:
def hexToBytes(str: String) =
str.grouped(2).map(cc => Integer.parseInt(cc, 16).toByte).toArray

Expand Down
2 changes: 1 addition & 1 deletion test-kit/src/test/scala/HistoryTest.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package chess

class HistoryTest extends ChessTest:
class HistoryTest extends ChessSpecs:

"threefold repetition" should:
def toHash(a: Int) = PositionHash(Array(a.toByte, 0.toByte, 0.toByte))
Expand Down
2 changes: 1 addition & 1 deletion test-kit/src/test/scala/HordeVariantTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import variant.Horde
import chess.format.EpdFen
import chess.format.pgn.SanStr

class HordeVariantTest extends ChessTest:
class HordeVariantTest extends ChessSpecs:

"Horde chess" should:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import InsufficientMatingMaterial.*
import chess.format.EpdFen
import chess.variant.Standard

class InsufficientMatingMaterialTest extends ChessTest:
class InsufficientMatingMaterialTest extends ChessSpecs:

"bishops on Opposite colors" should:

Expand Down
2 changes: 1 addition & 1 deletion test-kit/src/test/scala/KingSafetyTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package chess
import scala.language.implicitConversions
import Square.*

class KingSafetyTest extends ChessTest:
class KingSafetyTest extends ChessSpecs:

"in order to save the king" should:
"the king" in:
Expand Down
2 changes: 1 addition & 1 deletion test-kit/src/test/scala/KingTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package chess
import scala.language.implicitConversions
import Square.*

class KingTest extends ChessTest:
class KingTest extends ChessSpecs:

"a king" should:

Expand Down
2 changes: 1 addition & 1 deletion test-kit/src/test/scala/KnightTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package chess
import scala.language.implicitConversions
import Square.*

class KnightTest extends ChessTest:
class KnightTest extends ChessSpecs:

"a knight" should:

Expand Down
2 changes: 1 addition & 1 deletion test-kit/src/test/scala/PawnTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package chess
import Square.*
import format.Uci

class PawnTest extends ChessTest:
class PawnTest extends ChessSpecs:

"a white pawn" should:

Expand Down
2 changes: 1 addition & 1 deletion test-kit/src/test/scala/PieceTest.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package chess

class PieceTest extends ChessTest:
class PieceTest extends ChessSpecs:

"Piece" should:
"compare" in:
Expand Down
2 changes: 1 addition & 1 deletion test-kit/src/test/scala/PlayOneMoveTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package chess

import Square.*

class PlayOneMoveTest extends ChessTest:
class PlayOneMoveTest extends ChessSpecs:

"playing a move" should:
"only process things once" in:
Expand Down
2 changes: 1 addition & 1 deletion test-kit/src/test/scala/PlayTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import chess.Square.*
import chess.format.{ EpdFen, Fen }
import chess.variant.Standard

class PlayTest extends ChessTest:
class PlayTest extends ChessSpecs:

"playing a game" should:
"preserve castling rights" in:
Expand Down
2 changes: 1 addition & 1 deletion test-kit/src/test/scala/PlyTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package chess
// 2 rnbqkbnr/pp1ppppp/8/2p5/4P3/8/PPPP1PPP/RNBQKBNR w KQkq c6 0 2
// 3 rnbqkbnr/pp1ppppp/8/2p5/4P3/5N2/PPPP1PPP/RNBQKB1R b KQkq - 1 2

class PlyTest extends munit.FunSuite:
class PlyTest extends ChessTest:

test("to full move number"):
assertEquals(Ply(0).fullMoveNumber, FullMoveNumber(1)) // root
Expand Down
2 changes: 1 addition & 1 deletion test-kit/src/test/scala/PromotionTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import chess.format.EpdFen
import chess.Square.*
import chess.variant.Standard

class PromotionTest extends ChessTest:
class PromotionTest extends ChessSpecs:

"Not allow promotion to a king in a standard game " in:
val fen = EpdFen("8/1P6/8/8/8/8/7k/1K6 w - -")
Expand Down
2 changes: 1 addition & 1 deletion test-kit/src/test/scala/QueenTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package chess
import scala.language.implicitConversions
import Square.*

class QueenTest extends ChessTest:
class QueenTest extends ChessSpecs:

"a queen" should:

Expand Down
2 changes: 1 addition & 1 deletion test-kit/src/test/scala/RacingKingsVariantTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import variant.RacingKings

import chess.format.EpdFen

class RacingKingsVariantTest extends ChessTest:
class RacingKingsVariantTest extends ChessSpecs:

"Racing Kings" should:

Expand Down
2 changes: 1 addition & 1 deletion test-kit/src/test/scala/ReplayTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import chess.format.pgn.SanStr
import chess.variant.Chess960
import chess.format.pgn.Fixtures

class ReplayTest extends ChessTest:
class ReplayTest extends ChessSpecs:

"from prod" in:

Expand Down
2 changes: 1 addition & 1 deletion test-kit/src/test/scala/RookTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package chess
import scala.language.implicitConversions
import Square.*

class RookTest extends ChessTest:
class RookTest extends ChessSpecs:

"a rook" should:

Expand Down
2 changes: 1 addition & 1 deletion test-kit/src/test/scala/SituationTest.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package chess

class SituationTest extends ChessTest:
class SituationTest extends ChessSpecs:

"a game" should:
"detect check" should:
Expand Down
2 changes: 1 addition & 1 deletion test-kit/src/test/scala/UnmovedRooksTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import cats.syntax.all.*

import bitboard.Board as BBoard

class UnmovedRooksTest extends ChessTest:
class UnmovedRooksTest extends ChessSpecs:

"UnmovedRooks with 960 initial fen" in:
Fen
Expand Down
2 changes: 1 addition & 1 deletion test-kit/src/test/scala/VariantTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import chess.format.{ EpdFen, Fen }
import chess.variant.*
import org.specs2.specification.core.Fragment

class VariantTest extends ChessTest:
class VariantTest extends ChessSpecs:

val board = makeBoard

Expand Down
4 changes: 1 addition & 3 deletions test-kit/src/test/scala/bitboard/BoardTest.scala
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package chess
package bitboard

import munit.FunSuite

import Square.*
import Bitboard.*
import chess.format.Fen
import chess.format.EpdFen

class BoardTest extends FunSuite:
class BoardTest extends ChessTest:

import scala.language.implicitConversions
given Conversion[Square, Int] = _.value
Expand Down
2 changes: 1 addition & 1 deletion test-kit/src/test/scala/format/FenTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package format

import scala.language.implicitConversions

class FenTest extends ChessTest:
class FenTest extends ChessSpecs:

import pgn.Reader
import Square.*
Expand Down
Loading

0 comments on commit 8975550

Please sign in to comment.