2016-07-11 02:06:14 -04:00
|
|
|
package chart
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2024-10-27 22:52:38 -04:00
|
|
|
"git.smarteching.com/zeni/go-chart/v2/testutil"
|
2016-07-11 02:06:14 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestTimeValueFormatterWithFormat(t *testing.T) {
|
2020-11-22 19:45:10 -05:00
|
|
|
// replaced new assertions helper
|
2016-07-11 02:06:14 -04:00
|
|
|
|
|
|
|
d := time.Now()
|
2019-02-13 19:09:26 -05:00
|
|
|
di := TimeToFloat64(d)
|
2016-07-11 02:06:14 -04:00
|
|
|
df := float64(di)
|
|
|
|
|
2017-04-25 23:03:30 -04:00
|
|
|
s := formatTime(d, DefaultDateFormat)
|
|
|
|
si := formatTime(di, DefaultDateFormat)
|
|
|
|
sf := formatTime(df, DefaultDateFormat)
|
2020-11-22 19:45:10 -05:00
|
|
|
testutil.AssertEqual(t, s, si)
|
|
|
|
testutil.AssertEqual(t, s, sf)
|
2016-07-11 02:06:14 -04:00
|
|
|
|
|
|
|
sd := TimeValueFormatter(d)
|
|
|
|
sdi := TimeValueFormatter(di)
|
|
|
|
sdf := TimeValueFormatter(df)
|
2020-11-22 19:45:10 -05:00
|
|
|
testutil.AssertEqual(t, s, sd)
|
|
|
|
testutil.AssertEqual(t, s, sdi)
|
|
|
|
testutil.AssertEqual(t, s, sdf)
|
2016-07-11 02:06:14 -04:00
|
|
|
}
|
|
|
|
|
2016-08-05 23:44:40 -04:00
|
|
|
func TestFloatValueFormatter(t *testing.T) {
|
2020-11-22 19:45:10 -05:00
|
|
|
// replaced new assertions helper
|
|
|
|
testutil.AssertEqual(t, "1234.00", FloatValueFormatter(1234.00))
|
2016-08-05 23:44:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestFloatValueFormatterWithFloat32Input(t *testing.T) {
|
2020-11-22 19:45:10 -05:00
|
|
|
// replaced new assertions helper
|
|
|
|
testutil.AssertEqual(t, "1234.00", FloatValueFormatter(float32(1234.00)))
|
2016-08-05 23:44:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestFloatValueFormatterWithIntegerInput(t *testing.T) {
|
2020-11-22 19:45:10 -05:00
|
|
|
// replaced new assertions helper
|
|
|
|
testutil.AssertEqual(t, "1234.00", FloatValueFormatter(1234))
|
2016-08-05 23:44:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestFloatValueFormatterWithInt64Input(t *testing.T) {
|
2020-11-22 19:45:10 -05:00
|
|
|
// replaced new assertions helper
|
|
|
|
testutil.AssertEqual(t, "1234.00", FloatValueFormatter(int64(1234)))
|
2016-08-05 23:44:40 -04:00
|
|
|
}
|
|
|
|
|
2016-07-11 02:06:14 -04:00
|
|
|
func TestFloatValueFormatterWithFormat(t *testing.T) {
|
2020-11-22 19:45:10 -05:00
|
|
|
// replaced new assertions helper
|
2016-07-11 02:06:14 -04:00
|
|
|
|
|
|
|
v := 123.456
|
|
|
|
sv := FloatValueFormatterWithFormat(v, "%.3f")
|
2020-11-22 19:45:10 -05:00
|
|
|
testutil.AssertEqual(t, "123.456", sv)
|
|
|
|
testutil.AssertEqual(t, "123.000", FloatValueFormatterWithFormat(123, "%.3f"))
|
2016-07-11 02:06:14 -04:00
|
|
|
}
|
2023-05-22 11:37:57 -04:00
|
|
|
|
|
|
|
func TestExponentialValueFormatter(t *testing.T) {
|
2023-09-11 16:10:03 -04:00
|
|
|
testutil.AssertEqual(t, "1.23e+02", ExponentialValueFormatter(123.456))
|
|
|
|
testutil.AssertEqual(t, "1.24e+07", ExponentialValueFormatter(12421243.424))
|
|
|
|
testutil.AssertEqual(t, "4.50e-01", ExponentialValueFormatter(0.45))
|
2023-05-22 11:37:57 -04:00
|
|
|
}
|