forked from lichess-org/lila
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFeaturedTest.scala
106 lines (95 loc) · 2.2 KB
/
FeaturedTest.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package lila
package game
import game._
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 = DbGame(
game = chess.Game(chess.Variant.default),
whitePlayer = DbPlayer.white.copy(elo = 1600.some),
blackPlayer = DbPlayer.black,
ai = None,
creatorColor = chess.Color.White,
mode = chess.Mode.default,
variant = chess.Variant.default)
val game2 = game1.copy(
clock = chess.Clock(180,0).some,
turns = 11)
val game3 = game1.copy(
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_== 0f
}
}
"speed" in {
"game1" in {
speedHeuristic(game1) must_== 0
}
"game2" in {
speedHeuristic(game2) must_== 0.5f
}
"game3" in {
speedHeuristic(game3) must_== 1f
}
}
"progress" in {
"game1" in {
progressHeuristic(game1) must_== 1f
}
"game2" in {
progressHeuristic(game2) must_== 0.5f
}
"game3" in {
progressHeuristic(game3) must_== 0f
}
}
"score" in {
"game1" in {
score(game1) must_== 0.6f + 0f + 1f * 0.5f
}
"game2" in {
score(game2) must_== 0.6f + 0.5f + 0.5f * 0.5f
}
"game3" in {
score(game3) must_== 0.6f + 1f + 0f * 0.5f
}
}
"best" in {
"3 games" in {
best(games) must_== game3.some
}
"3 games reversed" in {
best(games.reverse) must_== game3.some
}
}
}
}