Created
March 20, 2023 21:23
-
-
Save lenguyenthanh/2cdfe56a9a8b7cb7387818160613cdd5 to your computer and use it in GitHub Desktop.
Tests never stop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8/8/8/8/8/8/8/k7 b - - 0 1 | true | white=0 | |
---|---|---|---|
8/8/3p4/5q2/8/8/q7/k7 b - - 0 1 | true | white=0 | |
8/8/3n4/5q2/8/8/q7/k7 b - - 0 1 | true | white=0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//> using scala "3.2.2" | |
//> using lib "org.typelevel::toolkit::0.0.3" | |
//> using repository "https://raw.githubusercontent.com/lichess-org/lila-maven/master" | |
//> using lib "org.lichess::scalachess:14.6.3" | |
import cats.effect.{IO, IOApp} | |
import cats.syntax.all.* | |
import cats.effect.syntax.all.* | |
import fs2.* | |
import fs2.io.file.Files | |
import cats.kernel.Monoid | |
import chess.format.Fen | |
import chess.format.EpdFen | |
import chess.variant.* | |
import munit.CatsEffectSuite | |
class HordeInsufficientMaterialTests extends CatsEffectSuite: | |
test("insufficient material tests") { | |
run("horde_white_insufficient_material_tests.csv", Horde).assert | |
} | |
given Monoid[Boolean] with | |
def empty = true | |
def combine(x: Boolean, y: Boolean) = x && y | |
private def run(file: String, variant: Variant): IO[Boolean] = | |
parser(file) | |
.foldMap(_.run(variant)) | |
.compile | |
.toList | |
.map(_.head) | |
private def parser(file: String): Stream[IO, Case] = | |
Files[IO] | |
.readAll(fs2.io.file.Path(file)) | |
.through(csvParser) | |
.map(parseSample) | |
private def csvParser[F[_]]: Pipe[F, Byte, List[String]] = | |
_.through(text.utf8Decode) | |
.through(text.lines) | |
.filter(_.nonEmpty) | |
.map(_.split(',').toList) | |
private def parseSample(sample: List[String]): Case = | |
Case(EpdFen(sample(0)), sample(1).toBoolean, sample.get(2)) | |
private case class Case(fen: EpdFen, expected: Boolean, comment: Option[String]) { | |
def run(variant: Variant): Boolean = | |
val situation = Fen.read(variant, fen).get | |
Horde.hasInsufficientMaterial(situation.board, !situation.color) == expected | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment