Debian Codegraph @

value_formatter_test.go

raw symbols SCIP
1 package chart
2
3 import (
4 "testing"
5 "time"
6
7 "github.com/wcharczuk/go-chart/v2/testutil"
8 )
9
10 func TestTimeValueFormatterWithFormat(t *testing.T) {
11 // replaced new assertions helper
12
13 d := time.Now()
14 di := TimeToFloat64(d)
15 df := float64(di)
16
17 s := formatTime(d, DefaultDateFormat)
18 si := formatTime(di, DefaultDateFormat)
19 sf := formatTime(df, DefaultDateFormat)
20 testutil.AssertEqual(t, s, si)
21 testutil.AssertEqual(t, s, sf)
22
23 sd := TimeValueFormatter(d)
24 sdi := TimeValueFormatter(di)
25 sdf := TimeValueFormatter(df)
26 testutil.AssertEqual(t, s, sd)
27 testutil.AssertEqual(t, s, sdi)
28 testutil.AssertEqual(t, s, sdf)
29 }
30
31 func TestFloatValueFormatter(t *testing.T) {
32 // replaced new assertions helper
33 testutil.AssertEqual(t, "1234.00", FloatValueFormatter(1234.00))
34 }
35
36 func TestFloatValueFormatterWithFloat32Input(t *testing.T) {
37 // replaced new assertions helper
38 testutil.AssertEqual(t, "1234.00", FloatValueFormatter(float32(1234.00)))
39 }
40
41 func TestFloatValueFormatterWithIntegerInput(t *testing.T) {
42 // replaced new assertions helper
43 testutil.AssertEqual(t, "1234.00", FloatValueFormatter(1234))
44 }
45
46 func TestFloatValueFormatterWithInt64Input(t *testing.T) {
47 // replaced new assertions helper
48 testutil.AssertEqual(t, "1234.00", FloatValueFormatter(int64(1234)))
49 }
50
51 func TestFloatValueFormatterWithFormat(t *testing.T) {
52 // replaced new assertions helper
53
54 v := 123.456
55 sv := FloatValueFormatterWithFormat(v, "%.3f")
56 testutil.AssertEqual(t, "123.456", sv)
57 testutil.AssertEqual(t, "123.000", FloatValueFormatterWithFormat(123, "%.3f"))
58 }
59
60 func TestExponentialValueFormatter(t *testing.T) {
61 testutil.AssertEqual(t, "1.23e+02", ExponentialValueFormatter(123.456))
62 testutil.AssertEqual(t, "1.24e+07", ExponentialValueFormatter(12421243.424))
63 testutil.AssertEqual(t, "4.50e-01", ExponentialValueFormatter(0.45))
64 }