2021-10-26 10:31:31 +00:00
|
|
|
package accounting_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2023-03-07 11:20:03 +00:00
|
|
|
v2accounting "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/accounting"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/accounting"
|
2021-10-26 10:31:31 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2022-03-12 16:15:26 +00:00
|
|
|
func TestDecimalData(t *testing.T) {
|
2021-10-26 10:31:31 +00:00
|
|
|
const v, p = 4, 2
|
|
|
|
|
2022-03-12 16:15:26 +00:00
|
|
|
var d accounting.Decimal
|
|
|
|
|
|
|
|
require.Zero(t, d.Value())
|
|
|
|
require.Zero(t, d.Precision())
|
|
|
|
|
2021-10-26 10:31:31 +00:00
|
|
|
d.SetValue(v)
|
|
|
|
d.SetPrecision(p)
|
|
|
|
|
|
|
|
require.EqualValues(t, v, d.Value())
|
|
|
|
require.EqualValues(t, p, d.Precision())
|
|
|
|
}
|
|
|
|
|
2022-03-12 16:15:26 +00:00
|
|
|
func TestDecimalMessageV2(t *testing.T) {
|
|
|
|
var (
|
|
|
|
d accounting.Decimal
|
|
|
|
m v2accounting.Decimal
|
|
|
|
)
|
2021-10-26 10:31:31 +00:00
|
|
|
|
2022-03-12 16:15:26 +00:00
|
|
|
m.SetValue(7)
|
|
|
|
m.SetPrecision(8)
|
2021-10-26 10:31:31 +00:00
|
|
|
|
2022-07-07 10:51:05 +00:00
|
|
|
require.NoError(t, d.ReadFromV2(m))
|
2021-10-26 10:31:31 +00:00
|
|
|
|
2022-03-12 16:15:26 +00:00
|
|
|
require.EqualValues(t, m.GetValue(), d.Value())
|
|
|
|
require.EqualValues(t, m.GetPrecision(), d.Precision())
|
2021-10-26 10:31:31 +00:00
|
|
|
|
2022-03-12 16:15:26 +00:00
|
|
|
var m2 v2accounting.Decimal
|
2021-10-26 10:31:31 +00:00
|
|
|
|
2022-03-17 13:45:26 +00:00
|
|
|
d.WriteToV2(&m2)
|
2021-10-26 10:31:31 +00:00
|
|
|
|
2022-03-12 16:15:26 +00:00
|
|
|
require.EqualValues(t, d.Value(), m2.GetValue())
|
|
|
|
require.EqualValues(t, d.Precision(), m2.GetPrecision())
|
2021-10-26 10:31:31 +00:00
|
|
|
}
|