9bebc1247d
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
51 lines
820 B
Go
51 lines
820 B
Go
package accounting
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestDecimal_Value(t *testing.T) {
|
|
d := NewDecimal()
|
|
|
|
v := int64(3)
|
|
d.SetValue(v)
|
|
|
|
require.Equal(t, v, d.Value())
|
|
}
|
|
|
|
func TestDecimal_Precision(t *testing.T) {
|
|
d := NewDecimal()
|
|
|
|
p := uint32(3)
|
|
d.SetPrecision(p)
|
|
|
|
require.Equal(t, p, d.Precision())
|
|
}
|
|
|
|
func TestDecimalEncoding(t *testing.T) {
|
|
d := NewDecimal()
|
|
d.SetValue(1)
|
|
d.SetPrecision(2)
|
|
|
|
t.Run("binary", func(t *testing.T) {
|
|
data, err := d.Marshal()
|
|
require.NoError(t, err)
|
|
|
|
d2 := NewDecimal()
|
|
require.NoError(t, d2.Unmarshal(data))
|
|
|
|
require.Equal(t, d, d2)
|
|
})
|
|
|
|
t.Run("json", func(t *testing.T) {
|
|
data, err := d.MarshalJSON()
|
|
require.NoError(t, err)
|
|
|
|
d2 := NewDecimal()
|
|
require.NoError(t, d2.UnmarshalJSON(data))
|
|
|
|
require.Equal(t, d, d2)
|
|
})
|
|
}
|