-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreality_test.go
More file actions
97 lines (84 loc) · 1.77 KB
/
reality_test.go
File metadata and controls
97 lines (84 loc) · 1.77 KB
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
package reality
import (
"fmt"
"math"
"testing"
)
type SimpleChartRepo struct {
data map[string]float64
}
func (s SimpleChartRepo) GetDifficulty(chartID string) (float64, error) {
ret, ok := s.data[chartID]
if !ok {
return 0, fmt.Errorf("chart not exist")
}
return ret, nil
}
var simpleChartRepo = SimpleChartRepo{
data: make(map[string]float64),
}
func init() {
simpleChartRepo.data["1"] = 2
}
type SimpleScoreRecord struct {
ChartID string
Score float64
}
func (s SimpleScoreRecord) GetChartID() string {
return s.ChartID
}
func (s SimpleScoreRecord) GetScore() float64 {
return s.Score
}
func TestSingleRecordValue(t *testing.T) {
score := SimpleScoreRecord{
ChartID: "1",
Score: 1005000,
}
result, err := CalculateSingleEntryReality(score, simpleChartRepo)
if err != nil {
t.Error(err)
}
if math.Abs(result-3.5) >= 1e8 {
t.Errorf("result should be 3.5")
}
}
func TestEmptyRecordReality(t *testing.T) {
result, err := CalculateReality([]ScoreRecord{}, simpleChartRepo)
if err != nil {
t.Error(err)
}
if math.Abs(result) >= 1e8 {
t.Errorf("result should be 3.5")
}
}
func TestSingleRecordReality(t *testing.T) {
score := SimpleScoreRecord{
ChartID: "1",
Score: 1005000,
}
result, err := CalculateReality([]ScoreRecord{score}, simpleChartRepo)
if err != nil {
t.Error(err)
}
if math.Abs(result-3.5/20) >= 1e8 {
t.Errorf("result should be 3.5")
}
}
func TestRecordRealityWithSingleValue(t *testing.T) {
score := SimpleScoreRecord{
ChartID: "1",
Score: 1005000,
}
scores := make([]ScoreRecord, 0)
for i := 0; i < 50; i++ {
scores = append(scores, score)
}
result, err := CalculateReality(scores, simpleChartRepo)
if err != nil {
t.Error(err)
}
if math.Abs(result-3.5) >= 1e8 {
t.Errorf("result should be 3.5")
}
}