2019-04-16 03:00:41 +00:00
|
|
|
package sparkline
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2019-04-21 04:15:03 +00:00
|
|
|
func TestSparkLine_trimOutOfRangeValues(t *testing.T) {
|
2019-04-16 03:00:41 +00:00
|
|
|
type Sparkline struct {
|
|
|
|
maxSize int
|
|
|
|
expectedSize int
|
|
|
|
values []float64
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
sparkline Sparkline
|
|
|
|
}{
|
2019-04-21 04:15:03 +00:00
|
|
|
{"should trimOutOfRangeValues values to the max size", Sparkline{maxSize: 5, expectedSize: 5, values: []float64{1, 2, 3, 4, 5, 6, 7, 8}}},
|
|
|
|
{"should not trimOutOfRangeValues values if max size is bigger than values len", Sparkline{maxSize: 5, expectedSize: 3, values: []float64{1, 2, 3}}},
|
2019-04-16 03:00:41 +00:00
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
s := &SparkLine{
|
|
|
|
values: tt.sparkline.values,
|
|
|
|
}
|
2019-04-21 04:15:03 +00:00
|
|
|
s.trimOutOfRangeValues(tt.sparkline.maxSize)
|
2019-04-16 03:00:41 +00:00
|
|
|
if len(s.values) != tt.sparkline.expectedSize {
|
2019-04-21 04:15:03 +00:00
|
|
|
t.Errorf("Values size after trimOutOfRangeValues is %v, but needed to be %v", len(s.values), tt.sparkline.expectedSize)
|
2019-04-16 03:00:41 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|