forked from wcharczuk/go-chart
-
Notifications
You must be signed in to change notification settings - Fork 2
/
value_formatter_test.go
59 lines (47 loc) · 1.36 KB
/
value_formatter_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package chart
import (
"testing"
"time"
"github.com/blend/go-sdk/assert"
"github.com/beevee/go-chart/util"
)
func TestTimeValueFormatterWithFormat(t *testing.T) {
assert := assert.New(t)
d := time.Now()
di := util.Time.ToFloat64(d)
df := float64(di)
s := formatTime(d, DefaultDateFormat)
si := formatTime(di, DefaultDateFormat)
sf := formatTime(df, DefaultDateFormat)
assert.Equal(s, si)
assert.Equal(s, sf)
sd := TimeValueFormatter(d)
sdi := TimeValueFormatter(di)
sdf := TimeValueFormatter(df)
assert.Equal(s, sd)
assert.Equal(s, sdi)
assert.Equal(s, sdf)
}
func TestFloatValueFormatter(t *testing.T) {
assert := assert.New(t)
assert.Equal("1234.00", FloatValueFormatter(1234.00))
}
func TestFloatValueFormatterWithFloat32Input(t *testing.T) {
assert := assert.New(t)
assert.Equal("1234.00", FloatValueFormatter(float32(1234.00)))
}
func TestFloatValueFormatterWithIntegerInput(t *testing.T) {
assert := assert.New(t)
assert.Equal("1234.00", FloatValueFormatter(1234))
}
func TestFloatValueFormatterWithInt64Input(t *testing.T) {
assert := assert.New(t)
assert.Equal("1234.00", FloatValueFormatter(int64(1234)))
}
func TestFloatValueFormatterWithFormat(t *testing.T) {
assert := assert.New(t)
v := 123.456
sv := FloatValueFormatterWithFormat(v, "%.3f")
assert.Equal("123.456", sv)
assert.Equal("123.000", FloatValueFormatterWithFormat(123, "%.3f"))
}