Skip to content

Commit

Permalink
Start unit testing grouper
Browse files Browse the repository at this point in the history
  • Loading branch information
clarkerubber committed Jan 6, 2015
1 parent 35ccebb commit 29c31ee
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 2 deletions.
7 changes: 6 additions & 1 deletion app/controllers/Analyse.scala
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ object Analyse extends LilaController {
if (HTTPRequest.isBot(ctx.req)) divider.empty
else divider(pov.game, initialFen)
val pgn = Env.game.pgnDump(pov.game, initialFen)
Env.api.roundApi.watcher(pov, Env.api.version, tv = none, analysis.map(pgn -> _), initialFen = initialFen.some) map { data =>
Env.api.roundApi.watcher(pov, Env.api.version, tv = none, analysis.map(pgn -> _), initialFen = initialFen.some) map { data => {
println(pov)
println(pov.game)
println(pov.game.moveTimes)
println(pov.game.players.map(_.blurs))
Ok(html.analyse.replay(
pov,
data,
Expand All @@ -76,6 +80,7 @@ object Analyse extends LilaController {
userTv,
division))
}
}
}
}
}
2 changes: 1 addition & 1 deletion modules/evaluation/src/main/Group.scala
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ object Statistics {
def allSimilar(a: NonEmptyList[Similarity]): Boolean = a.list.forall( _.isSimilar )

// Square Sum Distance
def ssd(a: NonEmptyList[Similarity]): Double = sqrt(a.map(x => pow(x.apply, 2)).list.sum)
def ssd(a: NonEmptyList[Similarity]): Double = sqrt(a.map(x => pow(x.apply, 2)).list.sum) / a.size
}

object Erf {
Expand Down
56 changes: 56 additions & 0 deletions modules/evaluation/src/test/GroupTest.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package lila.evaluation
package grouping

import org.specs2.specification._
import org.specs2.mutable._

import scalaz.NonEmptyList

class GroupTest extends Specification {
val game1 = GameGroup(
NonEmptyList(15, 40, 10, 30, 20, 40, 20, 80, 30, 30, 10, 40, 20, 60, 100, 80, 50, 30, 50, 5, 100, 300, 150, 50, 60, 20, 15, 15, 15, 60, 30, 80, 80, 150, 80, 200, 10, 80, 60, 150, 50, 30, 30, 150, 40, 40, 30, 30),
NonEmptyList(0, 1, 2, 1),
List(),
List()
)
val game2 = GameGroup(
NonEmptyList(15, 40, 10, 30, 20, 40, 20, 80, 30, 30, 10, 40, 20, 60, 100, 80, 50, 30, 50, 5, 100, 300, 150, 50, 60, 20, 15, 15, 15, 60, 30, 80, 80, 150, 80, 200, 10, 80, 60, 150, 50, 30, 30, 150, 40, 40, 30, 30),
NonEmptyList(0, 1, 2, 1),
List(),
List()
)

"Group similarityTo" should {
"match" in {
game1.similarityTo(game2) must_=={MatchAndSig(true, 1.0)}
}
}

"Group compareMoveTimes" should {
"match" in {
game1.compareMoveTimes(game2).isSimilar must_=={true}
game1.compareMoveTimes(game2).apply must_=={1.0}
}
}

"Group compareSfAccuracies" should {
"match" in {
game1.compareSfAccuracies(game2).isSimilar must_=={true}
game1.compareSfAccuracies(game2).apply must_=={1.0}
}
}

"Group compareBlurRates" should {
"match" in {
game1.compareBlurRates(game2).isSimilar must_=={true}
game1.compareBlurRates(game2).apply must_=={1.0}
}
}

"Group compareHoldAlerts" should {
"match" in {
game1.compareHoldAlerts(game2).isSimilar must_=={true}
game1.compareHoldAlerts(game2).apply must_=={1.0}
}
}
}

0 comments on commit 29c31ee

Please sign in to comment.