2016-07-06 21:54:00 -04:00
|
|
|
package chart
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2020-11-22 19:45:10 -05:00
|
|
|
"github.com/wcharczuk/go-chart/v2/testutil"
|
2016-07-06 21:54:00 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestRangeTranslate(t *testing.T) {
|
2020-11-22 19:45:10 -05:00
|
|
|
// replaced new assertions helper
|
2016-07-12 02:32:31 -04: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 17:11:27 -04:00
|
|
|
r := ContinuousRange{Domain: 1000}
|
2019-02-13 19:09:26 -05:00
|
|
|
r.Min, r.Max = MinMax(values...)
|
2016-07-12 02:32:31 -04:00
|
|
|
|
|
|
|
// delta = ~7.0
|
|
|
|
// value = ~5.0
|
|
|
|
// domain = ~1000
|
|
|
|
// 5/8 * 1000 ~=
|
2020-11-22 19:45:10 -05:00
|
|
|
testutil.AssertEqual(t, 0, r.Translate(1.0))
|
|
|
|
testutil.AssertEqual(t, 1000, r.Translate(8.0))
|
|
|
|
testutil.AssertEqual(t, 572, r.Translate(5.0))
|
2016-07-06 21:54:00 -04:00
|
|
|
}
|