2016-07-07 03:54:00 +02:00
|
|
|
package chart
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/blendlabs/go-assert"
|
2017-05-13 02:12:23 +02:00
|
|
|
"github.com/wcharczuk/go-chart/util"
|
2016-07-07 03:54:00 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestRangeTranslate(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
2016-07-12 08:32:31 +02:00
|
|
|
values := []float64{1.0, 2.0, 2.5, 2.7, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0}
|
2016-07-21 23:11:27 +02:00
|
|
|
r := ContinuousRange{Domain: 1000}
|
2017-05-13 02:12:23 +02:00
|
|
|
r.Min, r.Max = util.Math.MinAndMax(values...)
|
2016-07-12 08:32:31 +02:00
|
|
|
|
|
|
|
// delta = ~7.0
|
|
|
|
// value = ~5.0
|
|
|
|
// domain = ~1000
|
|
|
|
// 5/8 * 1000 ~=
|
|
|
|
assert.Equal(0, r.Translate(1.0))
|
|
|
|
assert.Equal(1000, r.Translate(8.0))
|
|
|
|
assert.Equal(572, r.Translate(5.0))
|
2016-07-07 03:54:00 +02:00
|
|
|
}
|