-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpowercurve_test.go
86 lines (77 loc) · 2.08 KB
/
powercurve_test.go
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
package main
import (
"math"
"testing"
)
func TestMain(t *testing.T) {
//main()
}
func TestSum(t *testing.T) {
input := []int{2, 4, 6, 8, 9, 9, 7, 5, 3, 1, 0}
testdata := makedata(input)
total, count := sum(testdata)
if total != 54 {
t.Fatal("cant add up")
}
if count != 11 {
t.Fatal("cant count")
}
}
func makedata(data []int) []power {
var result = make([]power, 0)
var foo power
for k, v := range data {
foo = power{k, float64(v)}
result = append(result, foo)
}
return result
}
func comparefloat(a float64, b float64) bool {
if math.Abs(a-b) < 0.00001 {
return true
}
return false
}
func TestAlgorithm(t *testing.T) {
input := []int{2, 4, 6, 8, 9, 9, 7, 5, 3, 1, 0}
testdata := makedata(input)
result := calculate(testdata)
// expect to return the peak power output
expect := 9.0
value := result[len(result)-1].Power
if !comparefloat(expect, value) {
t.Fatal("expecting", expect, "as peak power got", value)
}
}
func Test_short(t *testing.T) {
input := []int{2, 4}
testdata := makedata(input)
result := calculate(testdata)
// expect to return the peak power output
expect := 3.0
value := result[len(result)-1].Power
if !comparefloat(expect, value) {
t.Fatal("expecting", expect, " as peak power got", value)
}
}
func Test_scanner(t *testing.T) {
readTcx("input.tcx")
}
func Test_tcx(t *testing.T) {
data := readTcx("input.tcx")
result := calculate(data)
if len(result) == 0 {
t.Fatal("didnt read any lines ")
}
}
func Test_split(t *testing.T) {
input := "<Trackpoint><Time>2018-06-25T09:40:11.000Z</Time><DistanceMeters>0.0</DistanceMeters><Cadence>0</Cadence><Extensions><ns2:TPX><ns2:Speed>0.0</ns2:Speed><ns2:Watts>0</ns2:Watts></ns2:TPX></Extensions></Trackpoint><Trackpoint><Time>2018-06-25T09:40:12.000Z</Time><DistanceMeters>0.0</DistanceMeters><Cadence>0</Cadence><Extensions><ns2:TPX><ns2:Speed>0.0</ns2:Speed><ns2:Watts>0</ns2:Watts></ns2:TPX></Extensions></Trackpoint>"
data := extractData([]byte(input))
if len(data) != 2 {
t.Fatal("didnt read any lines ")
}
result := calculate(data)
if len(result) != 1 {
t.Fatal("didnt process the data")
}
}