fathom/pkg/count/count_test.go

43 lines
810 B
Go
Raw Normal View History

2016-12-11 13:33:05 +00:00
package count
2016-12-11 13:50:01 +00:00
import (
"testing"
"time"
2016-12-11 13:33:05 +00:00
)
func TestFill(t *testing.T) {
2016-12-11 13:50:01 +00:00
start := time.Date(2016, time.January, 1, 0, 0, 0, 0, time.Local)
end := time.Date(2016, time.January, 5, 0, 0, 0, 0, time.Local)
2016-12-11 13:33:05 +00:00
2016-12-11 13:50:01 +00:00
points := []Point{
Point{
Label: start.Format("2006-01-02"),
2016-12-11 13:50:01 +00:00
Value: 1,
},
Point{
Label: end.Format("2006-01-02"),
2016-12-11 13:50:01 +00:00
Value: 1,
},
}
2016-12-11 13:33:05 +00:00
2016-12-11 13:50:01 +00:00
filled := fill(start.Unix(), end.Unix(), points)
if len(filled) != 5 {
t.Error("Length of filled points slice does not match expected length")
}
}
func TestCalculatePointPercentages(t *testing.T) {
points := []Point{
Point{
Label: "Foo",
Value: 5,
},
}
2016-12-11 13:33:05 +00:00
points = calculatePointPercentages(points, 100)
if points[0].PercentageValue != 5.00 {
t.Errorf("Percentage value should be 5.00, is %.2f", points[0].PercentageValue)
}
2016-12-11 13:33:05 +00:00
}