2016-07-28 19:36:30 -04:00
|
|
|
package chart
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2018-04-05 03:42:38 -04:00
|
|
|
assert "github.com/blend/go-sdk/assert"
|
2016-07-28 19:36:30 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestValuesValues(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
vs := []Value{
|
|
|
|
{Value: 10, Label: "Blue"},
|
|
|
|
{Value: 9, Label: "Green"},
|
|
|
|
{Value: 8, Label: "Gray"},
|
|
|
|
{Value: 7, Label: "Orange"},
|
|
|
|
{Value: 6, Label: "HEANG"},
|
|
|
|
{Value: 5, Label: "??"},
|
|
|
|
{Value: 2, Label: "!!"},
|
|
|
|
}
|
|
|
|
|
|
|
|
values := Values(vs).Values()
|
2018-04-05 03:47:39 -04:00
|
|
|
assert.Len(7, values)
|
2016-07-28 19:36:30 -04:00
|
|
|
assert.Equal(10, values[0])
|
|
|
|
assert.Equal(9, values[1])
|
|
|
|
assert.Equal(8, values[2])
|
|
|
|
assert.Equal(7, values[3])
|
|
|
|
assert.Equal(6, values[4])
|
|
|
|
assert.Equal(5, values[5])
|
|
|
|
assert.Equal(2, values[6])
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestValuesValuesNormalized(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
vs := []Value{
|
|
|
|
{Value: 10, Label: "Blue"},
|
|
|
|
{Value: 9, Label: "Green"},
|
|
|
|
{Value: 8, Label: "Gray"},
|
|
|
|
{Value: 7, Label: "Orange"},
|
|
|
|
{Value: 6, Label: "HEANG"},
|
|
|
|
{Value: 5, Label: "??"},
|
|
|
|
{Value: 2, Label: "!!"},
|
|
|
|
}
|
|
|
|
|
|
|
|
values := Values(vs).ValuesNormalized()
|
2018-04-05 03:47:39 -04:00
|
|
|
assert.Len(7, values)
|
2016-07-28 21:56:45 -04:00
|
|
|
assert.Equal(0.2127, values[0])
|
|
|
|
assert.Equal(0.0425, values[6])
|
2016-07-28 19:36:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestValuesNormalize(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
vs := []Value{
|
|
|
|
{Value: 10, Label: "Blue"},
|
|
|
|
{Value: 9, Label: "Green"},
|
|
|
|
{Value: 8, Label: "Gray"},
|
|
|
|
{Value: 7, Label: "Orange"},
|
|
|
|
{Value: 6, Label: "HEANG"},
|
|
|
|
{Value: 5, Label: "??"},
|
|
|
|
{Value: 2, Label: "!!"},
|
|
|
|
}
|
|
|
|
|
|
|
|
values := Values(vs).Normalize()
|
2018-04-05 03:47:39 -04:00
|
|
|
assert.Len(7, values)
|
2016-07-28 21:56:45 -04:00
|
|
|
assert.Equal(0.2127, values[0].Value)
|
|
|
|
assert.Equal(0.0425, values[6].Value)
|
2016-07-28 19:36:30 -04:00
|
|
|
}
|