2020-03-10 20:42:11 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package currency
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
2020-03-31 21:30:39 +01:00
|
|
|
|
|
|
|
"storj.io/common/strictcsv"
|
2020-03-10 20:42:11 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestMicroUnitToFloatString(t *testing.T) {
|
|
|
|
require.Equal(t, "1.002332", NewMicroUnit(1002332).FloatString())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMicroUnitFromFloatString(t *testing.T) {
|
|
|
|
m, err := MicroUnitFromFloatString("0.012340")
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, NewMicroUnit(12340), m)
|
|
|
|
}
|
2020-03-31 21:30:39 +01:00
|
|
|
|
|
|
|
func TestMicroUnitCSV(t *testing.T) {
|
|
|
|
type row struct {
|
|
|
|
Foo MicroUnit `csv:"foo"`
|
|
|
|
Bar MicroUnit `csv:"bar"`
|
|
|
|
}
|
|
|
|
exp := row{
|
|
|
|
Foo: NewMicroUnit(1),
|
|
|
|
Bar: NewMicroUnit(2),
|
|
|
|
}
|
|
|
|
|
|
|
|
csv, err := strictcsv.MarshalString(exp)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
var got row
|
|
|
|
require.NoError(t, strictcsv.UnmarshalString(csv, &got))
|
|
|
|
require.Equal(t, exp, got)
|
|
|
|
}
|