| 1 |
package chart |
| 2 |
|
| 3 |
import ( |
| 4 |
"testing" |
| 5 |
|
| 6 |
"github.com/wcharczuk/go-chart/v2/testutil" |
| 7 |
) |
| 8 |
|
| 9 |
func TestGenerateContinuousTicks(t *testing.T) { |
| 10 |
|
| 11 |
|
| 12 |
f, err := GetDefaultFont() |
| 13 |
testutil.AssertNil(t, err) |
| 14 |
|
| 15 |
r, err := PNG(1024, 1024) |
| 16 |
testutil.AssertNil(t, err) |
| 17 |
r.SetFont(f) |
| 18 |
|
| 19 |
ra := &ContinuousRange{ |
| 20 |
Min: 0.0, |
| 21 |
Max: 10.0, |
| 22 |
Domain: 256, |
| 23 |
} |
| 24 |
|
| 25 |
vf := FloatValueFormatter |
| 26 |
|
| 27 |
ticks := GenerateContinuousTicks(r, ra, false, Style{}, vf) |
| 28 |
testutil.AssertNotEmpty(t, ticks) |
| 29 |
testutil.AssertLen(t, ticks, 11) |
| 30 |
testutil.AssertEqual(t, 0.0, ticks[0].Value) |
| 31 |
testutil.AssertEqual(t, 10, ticks[len(ticks)-1].Value) |
| 32 |
} |
| 33 |
|
| 34 |
func TestGenerateContinuousTicksDescending(t *testing.T) { |
| 35 |
|
| 36 |
|
| 37 |
f, err := GetDefaultFont() |
| 38 |
testutil.AssertNil(t, err) |
| 39 |
|
| 40 |
r, err := PNG(1024, 1024) |
| 41 |
testutil.AssertNil(t, err) |
| 42 |
r.SetFont(f) |
| 43 |
|
| 44 |
ra := &ContinuousRange{ |
| 45 |
Min: 0.0, |
| 46 |
Max: 10.0, |
| 47 |
Domain: 256, |
| 48 |
Descending: true, |
| 49 |
} |
| 50 |
|
| 51 |
vf := FloatValueFormatter |
| 52 |
|
| 53 |
ticks := GenerateContinuousTicks(r, ra, false, Style{}, vf) |
| 54 |
testutil.AssertNotEmpty(t, ticks) |
| 55 |
testutil.AssertLen(t, ticks, 11) |
| 56 |
testutil.AssertEqual(t, 10.0, ticks[0].Value) |
| 57 |
testutil.AssertEqual(t, 9.0, ticks[1].Value) |
| 58 |
testutil.AssertEqual(t, 1.0, ticks[len(ticks)-2].Value) |
| 59 |
testutil.AssertEqual(t, 0.0, ticks[len(ticks)-1].Value) |
| 60 |
} |