| 1 |
package chart |
| 2 |
|
| 3 |
import ( |
| 4 |
"fmt" |
| 5 |
"testing" |
| 6 |
|
| 7 |
"github.com/wcharczuk/go-chart/v2/testutil" |
| 8 |
) |
| 9 |
|
| 10 |
func TestContinuousSeries(t *testing.T) { |
| 11 |
|
| 12 |
|
| 13 |
cs := ContinuousSeries{ |
| 14 |
Name: "Test Series", |
| 15 |
XValues: LinearRange(1.0, 10.0), |
| 16 |
YValues: LinearRange(1.0, 10.0), |
| 17 |
} |
| 18 |
|
| 19 |
testutil.AssertEqual(t, "Test Series", cs.GetName()) |
| 20 |
testutil.AssertEqual(t, 10, cs.Len()) |
| 21 |
x0, y0 := cs.GetValues(0) |
| 22 |
testutil.AssertEqual(t, 1.0, x0) |
| 23 |
testutil.AssertEqual(t, 1.0, y0) |
| 24 |
|
| 25 |
xn, yn := cs.GetValues(9) |
| 26 |
testutil.AssertEqual(t, 10.0, xn) |
| 27 |
testutil.AssertEqual(t, 10.0, yn) |
| 28 |
|
| 29 |
xn, yn = cs.GetLastValues() |
| 30 |
testutil.AssertEqual(t, 10.0, xn) |
| 31 |
testutil.AssertEqual(t, 10.0, yn) |
| 32 |
} |
| 33 |
|
| 34 |
func TestContinuousSeriesValueFormatter(t *testing.T) { |
| 35 |
|
| 36 |
|
| 37 |
cs := ContinuousSeries{ |
| 38 |
XValueFormatter: func(v interface{}) string { |
| 39 |
return fmt.Sprintf("%f foo", v) |
| 40 |
}, |
| 41 |
YValueFormatter: func(v interface{}) string { |
| 42 |
return fmt.Sprintf("%f bar", v) |
| 43 |
}, |
| 44 |
} |
| 45 |
|
| 46 |
xf, yf := cs.GetValueFormatters() |
| 47 |
testutil.AssertEqual(t, "0.100000 foo", xf(0.1)) |
| 48 |
testutil.AssertEqual(t, "0.100000 bar", yf(0.1)) |
| 49 |
} |
| 50 |
|
| 51 |
func TestContinuousSeriesValidate(t *testing.T) { |
| 52 |
|
| 53 |
|
| 54 |
cs := ContinuousSeries{ |
| 55 |
Name: "Test Series", |
| 56 |
XValues: LinearRange(1.0, 10.0), |
| 57 |
YValues: LinearRange(1.0, 10.0), |
| 58 |
} |
| 59 |
testutil.AssertNil(t, cs.Validate()) |
| 60 |
|
| 61 |
cs = ContinuousSeries{ |
| 62 |
Name: "Test Series", |
| 63 |
XValues: LinearRange(1.0, 10.0), |
| 64 |
} |
| 65 |
testutil.AssertNotNil(t, cs.Validate()) |
| 66 |
|
| 67 |
cs = ContinuousSeries{ |
| 68 |
Name: "Test Series", |
| 69 |
YValues: LinearRange(1.0, 10.0), |
| 70 |
} |
| 71 |
testutil.AssertNotNil(t, cs.Validate()) |
| 72 |
} |