2020-11-16 13:35:34 +00:00
|
|
|
package accounting_test
|
2020-11-13 10:36:18 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2020-11-16 13:35:34 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/accounting"
|
2021-06-08 08:04:35 +00:00
|
|
|
accountingtest "github.com/nspcc-dev/neofs-api-go/pkg/accounting/test"
|
2020-11-13 10:36:18 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestDecimal_Value(t *testing.T) {
|
2020-11-16 13:35:34 +00:00
|
|
|
d := accounting.NewDecimal()
|
2020-11-13 10:36:18 +00:00
|
|
|
|
|
|
|
v := int64(3)
|
|
|
|
d.SetValue(v)
|
|
|
|
|
|
|
|
require.Equal(t, v, d.Value())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDecimal_Precision(t *testing.T) {
|
2020-11-16 13:35:34 +00:00
|
|
|
d := accounting.NewDecimal()
|
2020-11-13 10:36:18 +00:00
|
|
|
|
|
|
|
p := uint32(3)
|
|
|
|
d.SetPrecision(p)
|
|
|
|
|
|
|
|
require.Equal(t, p, d.Precision())
|
|
|
|
}
|
2020-11-13 10:38:49 +00:00
|
|
|
|
|
|
|
func TestDecimalEncoding(t *testing.T) {
|
2021-06-08 08:04:35 +00:00
|
|
|
d := accountingtest.Generate()
|
2020-11-13 10:38:49 +00:00
|
|
|
|
|
|
|
t.Run("binary", func(t *testing.T) {
|
|
|
|
data, err := d.Marshal()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2020-11-16 13:35:34 +00:00
|
|
|
d2 := accounting.NewDecimal()
|
2020-11-13 10:38:49 +00:00
|
|
|
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)
|
|
|
|
|
2020-11-16 13:35:34 +00:00
|
|
|
d2 := accounting.NewDecimal()
|
2020-11-13 10:38:49 +00:00
|
|
|
require.NoError(t, d2.UnmarshalJSON(data))
|
|
|
|
|
|
|
|
require.Equal(t, d, d2)
|
|
|
|
})
|
|
|
|
}
|