mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2026-02-06 07:19:37 +00:00
国际象棋 (#720)
* init commit for chess
* fix lint & error
* remove issue link
* fix lint
* remove embed
* regex fix
* use strings.Builder
* 改不动了,先 push 了备份下
* 基本上改好了
* limit
* 使用等宽字体渲染棋盘
* use syncx
* 不会更新依赖库😭
* 先 push 备份下
* 更新依赖版本,确保能读取到字体文件
* fix log
This commit is contained in:
80
plugin/chess/elo_test.go
Normal file
80
plugin/chess/elo_test.go
Normal file
@@ -0,0 +1,80 @@
|
||||
package chess
|
||||
|
||||
import (
|
||||
"math"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestCalculateNewRate(t *testing.T) {
|
||||
type args struct {
|
||||
whiteRate int
|
||||
blackRate int
|
||||
whiteScore float64
|
||||
blackScore float64
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want int
|
||||
want1 int
|
||||
}{
|
||||
{
|
||||
name: "test1",
|
||||
args: args{
|
||||
whiteRate: 1613,
|
||||
blackRate: 1573,
|
||||
whiteScore: 0.5,
|
||||
blackScore: 0.5,
|
||||
},
|
||||
want: 1611,
|
||||
want1: 1575,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, got1 := calculateNewRate(tt.args.whiteRate, tt.args.blackRate, tt.args.whiteScore, tt.args.blackScore)
|
||||
if got != tt.want {
|
||||
t.Errorf("CalculateNewRate() got = %v, want %v", got, tt.want)
|
||||
}
|
||||
if got1 != tt.want1 {
|
||||
t.Errorf("CalculateNewRate() got1 = %v, want %v", got1, tt.want1)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_calculateException(t *testing.T) {
|
||||
type args struct {
|
||||
rate int
|
||||
opponentRate int
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want float64
|
||||
}{
|
||||
{
|
||||
name: "test1",
|
||||
args: args{
|
||||
rate: 1613,
|
||||
opponentRate: 1573,
|
||||
},
|
||||
want: 0.5573116,
|
||||
},
|
||||
{
|
||||
name: "test2",
|
||||
args: args{
|
||||
rate: 1613,
|
||||
opponentRate: 1613,
|
||||
},
|
||||
want: 0.5,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := calculateException(tt.args.rate, tt.args.opponentRate); math.Abs(got-tt.want) > 0.0001 {
|
||||
t.Errorf("calculateException() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user