ZeroBot-Plugin/plugin/chess/elo_test.go
Aimer Neige ba0ef37b74
国际象棋 (#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
2023-09-01 22:21:07 +08:00

81 lines
1.4 KiB
Go

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)
}
})
}
}