fix some tests and remove others

pull/95/head
Thibault Duplessis 2014-07-24 00:29:23 +02:00
parent 2816b3fd33
commit 07185ce736
7 changed files with 4 additions and 253 deletions

View File

@ -39,7 +39,7 @@ final class UciToPgnTest extends Specification with ValidationMatchers {
Info(26, Some(Score(-2165)), None, List()),
Info(27, Some(Score(-2731)), None, List("g1g3", "h4h2", "d1f3", "e4g3", "c2c3", "h2g1", "e1d2", "g3e4", "d2c2", "e6g4", "f3g4", "g1g4", "b1d2", "g4e2", "a2a4", "a8e8", "a1a3", "e4d2", "c1d2", "e8e3")),
Info(28, None, Some(2), List("h4f2", "e2d3", "c6b4")),
Info(29, None, Some(-2), List())), true)
Info(29, None, Some(-2), List())), true, date = org.joda.time.DateTime.now)
val pgn = "d4 d5 f3 e6 f4 g6 g3 Bg7 Nf3 Nf6 e3 O-O Bh3 Nc6 g4 h6 g5 hxg5 Nxg5 Ne4 Bxe6 fxe6 Nxe6 Bxe6 Rg1 Qh4+ Ke2 Qxh2+ Kd3 Nb4#"
val rep = Reader(pgn).toOption.get

@ -1 +1 @@
Subproject commit f7ce76a5e56b8946a7902f1604a69926ee738a4f
Subproject commit 1195dad3ef7a2d3995e5efeaac1fef3d2b5e08e0

View File

@ -11,10 +11,8 @@ trait WithColl {
def withColl[A](f: Coll => A): A = {
implicit val ec = ExecutionContext.Implicits.global
val conn = new MongoDriver connection List("localhost:27017")
val db = conn("lila-test")
val db = conn("lila-test")
db.drop.await
val coll = db("test_" + ornicar.scalalib.Random.nextString(8))
val res = f(coll)

View File

@ -56,7 +56,7 @@ class BinaryClockTest extends Specification {
val c3 = clock.giveTime(chess.Black, 5)
isomorphism(c3) must_== c3
val c4 = clock.run
val c4 = clock.start
isomorphism(c4).timerOption.get must beCloseTo(c4.timerOption.get, 1)
Clock(2, 60) |> { c =>

View File

@ -1,48 +0,0 @@
package lila.game
import scala.concurrent.duration._
import chess.{ AllPieces }
import org.specs2.mutable._
import org.specs2.specification._
import reactivemongo.api.collections.default.BSONCollection
import lila.db.WithColl
class BinaryPieceDbTest extends Specification with WithColl {
val id = "00000000"
private def saveAndGet(repo: GameRepo, game: Game): AllPieces =
(repo.insertDenormalized(game) >> repo.game(game.id))
.flatten(s"Game ${game.id} not found")
.map(_.toChess.allPieces)
.await(Duration(1, SECONDS))
private def makeRepo(c: BSONCollection) =
new GameRepo { def gameTube = Game.tube inColl c }
"binary pieces" should {
"standard initial" in {
val g = Game.make(
game = chess.Game(chess.Variant.Standard),
whitePlayer = Player.white,
blackPlayer = Player.black,
mode = chess.Mode.default,
variant = chess.Variant.default,
source = Source.Lobby,
pgnImport = None)
withColl { c =>
saveAndGet(makeRepo(c), g) must_== g.toChess.allPieces
}
}
// "support real game" in {
// val moveString = "d4 e6 e3 d6 a3 Nf6 Nf3 Be7 Nc3 O-O h3 Nfd7 g3 d5 Bg2 c5 O-O cxd4 Qxd4 b6 Qd1 Ba6 Re1 Nc6 Bf1 f6 Bxa6 Nde5 Nxe5 Nxe5 b3 Rc8 Bb2 Rc6 Bb5 Rc5 b4 Rc7 f4 Nc4 Bxc4 Rxc4 h4 a6 b5 axb5 Nxb5 Rc5 a4 e5 Ba3 Rc4 Bxe7 Qxe7 fxe5 fxe5 Rf1 d4 Rxf8+ Qxf8 exd4 Qf3 Qf1 Qe3+ Qf2 Qxf2+ Kxf2 exd4 Rc1 d3 cxd3 Rxc1 Ke3 Ra1 Nc3 Ra3 Kd4 g6 Kc4 Kf7 d4 Ke6 d5+ Kd6 Kb5 Rb3+ Ka6 Rxc3 Kxb6 Kxd5 a5 Ra3 a6 Kd6 a7 Kd7 Kb7 Rb3+ Ka6 Ra3+ Kb7 Rb3+ Ka8 Kc7 g4 Rb4 h5 gxh5 gxh5 Ra4 h6 Rxa7+ Kxa7 Kd6 Kb7 Ke6 Kc6 Kf6 Kd5 Kg6 Ke5 Kxh6 Kf4 Kg6 Kg4 h6 Kh4 h5 Kg3 Kg5 Kh3 h4 Kg2 Kg4 Kh2 h3 Kg1 Kg3 Kh1 Kh4 Kh2 Kg4 Kh1 Kg3 Kg1 Kf3 Kh1 Kg4 Kh2 Kh4 Kg1 Kg3 Kh1 h2"
// val moves = moveString.split(' ').toList
// withColl { c =>
// val repo = new PgnRepo { def coll = c }
// saveAndGet(repo, moves) must_== moves
// }
// }
}
}

View File

@ -1,91 +0,0 @@
package lila.game
import org.specs2.mutable._
import org.specs2.specification._
import play.api.libs.json._
import play.modules.reactivemongo.json.ImplicitBSONHandlers.JsObjectWriter
import lila.db.ByteArray
class PerfTest extends Specification {
val nb = 200
// val nb = 2
val iterations = 10
// val iterations = 1
def runOne = Game.tube read getBson map (_.toChess)
def run { for (i 1 to nb) runOne }
"game model" should {
"work" in {
(Game.gameBSONHandler read getBson).turns must_== 12
}
"be fast" in {
if (nb * iterations > 1) {
print("warming up")
run
println(" again")
run
}
println("measuring")
val durations = for (i 1 to iterations) yield {
val start = System.currentTimeMillis
run
val duration = System.currentTimeMillis - start
println(s"$nb games in $duration ms")
duration
}
val nbGames = iterations * nb
val gameMicros = (1000 * durations.sum) / nbGames
println(s"Average = $gameMicros micros per game")
println(s" ${1000000 / gameMicros} games per second")
true must_== true
}
}
private def getBson = Game.gameBSONHandler write getGame
private def getGame = {
import chess.{ RunningClock, Board, Variant, Color, Pos, Status, Castles, Mode }
import org.joda.time.DateTime
Game(
id = "s9kgwwwq",
clock = RunningClock(
color = Color.Black,
limit = 420,
increment = 0,
whiteTime = 13.557001f,
blackTime = 68.216995f,
timer = 1371840910d).some,
createdAt = DateTime.now,
castleLastMoveTime = CastleLastMoveTime(
Castles.all,
lastMove = Some(Pos.A7 -> Pos.A5),
lastMoveTime = Some(300),
check = None),
metadata = Metadata(Source.Lobby.some, None, None, None),
whitePlayer = Player(
color = Color.White,
id = "4xqm",
elo = 1151.some,
blurs = 1,
userId = "red1".some,
aiLevel = None),
blackPlayer = Player(
color = Color.Black,
id = "ufh0",
elo = 968.some,
userId = "japr".some,
aiLevel = None),
moveTimes = Vector(100, 20, 10, 60, 30, 30, 40, 100, 120, 10, 30),
binaryPieces = BinaryFormat.piece write {
Board.init(Variant.Standard).pieces -> Nil
},
binaryPgn = ByteArray.empty,
mode = Mode(true),
status = Status.Started,
turns = 12,
updatedAt = DateTime.now.some)
}
}

View File

@ -1,108 +0,0 @@
package lila
package game
import lila.user._
class FeaturedTest extends LilaSpec {
import Featured._
"Featured" should {
"box 0 to 1" in {
foreach(List(
0f -> 0f,
1f -> 1f,
0.5f -> 0.5f,
0.9f -> 0.9f,
-1f -> 0f,
2f -> 1f)) {
case (a, b) => box(0 to 1)(a) must_== b
}
}
"box 1200 to 2000" in {
foreach(List(
1200f -> 0f,
2000f -> 1f,
1600f -> 0.5f,
1900f -> 0.875f,
-1f -> 0f,
800f -> 0f,
2200f -> 1f)) {
case (a, b) => box(1200 to 2000)(a) must_== b
}
}
val game1 = Game.make(
game = chess.Game(chess.Variant.default),
whitePlayer = Player.white.copy(elo = 1600.some),
blackPlayer = Player.black,
mode = chess.Mode.default,
variant = chess.Variant.default,
source = Source.Lobby,
pgnImport = None).copy(id = "game1")
val game2 = game1.copy(
id = "game2",
clock = chess.Clock(180,0).some,
turns = 11)
val game3 = game1.copy(
id = "game3",
clock = chess.Clock(60,0).some,
turns = 21)
val games = List(game1, game2, game3)
"elo" in {
"game1 white" in {
eloHeuristic(chess.Color.White)(game1) must_== 0.6f
}
"game1 black" in {
eloHeuristic(chess.Color.Black)(game1) must_== 0.1f
}
}
"speed" in {
"game1" in {
speedHeuristic(game1) must_== 0
}
"game2" in {
speedHeuristic(game2) must_== 0.6f
}
"game3" in {
speedHeuristic(game3) must_== 1f
}
}
"progress" in {
"game1" in {
progressHeuristic(game1) must_== 1f
}
"game2" in {
progressHeuristic(game2) must beCloseTo(0.5f, 0.1f)
}
"game3" in {
progressHeuristic(game3) must beCloseTo(0.1f, 0.1f)
}
}
"score" in {
"game1" in {
score(game1) must_== 1700
}
"game2" in {
score(game2) must_== 1583
}
"game3" in {
score(game3) must_== 1367
}
}
"best" in {
"3 games" in {
sort(games).headOption must_== game1.some
}
"3 games reversed" in {
sort(games.reverse).headOption must_== game1.some
}
}
}
}