Files
Gumble-Backend/internal/util/currency_test.go
Zane Walker 7e940c83a7
Some checks failed
Build & Test / build-test (push) Has been cancelled
Build & Test / swagger-codegen-cli (push) Has been cancelled
CodeQL / Analyze (go) (push) Has been cancelled
(Feat): Initial Commit
2026-07-03 19:41:31 +05:30

67 lines
1.3 KiB
Go

package util_test
import (
"testing"
"allaboutapps.dev/aw/go-starter/internal/util"
"github.com/stretchr/testify/assert"
)
func TestCurrencyConversion(t *testing.T) {
tests := []struct {
name string
val int
}{
{
name: "1",
val: 999999999999999, // this is the max size with accurate precision
},
{
name: "2",
val: 0,
},
{
name: "3",
val: -999999999999999,
},
{
name: "4",
val: 3333333333333333,
},
{
name: "5",
val: 1111111111111111,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
in := int64(tt.val)
res := util.Int64PtrWithCentsToFloat64Ptr(&in)
out := util.Float64PtrToInt64PtrWithCents(res)
assert.Equal(t, in, *out)
inInt := int(in)
res = util.IntPtrWithCentsToFloat64Ptr(&inInt)
outInt := util.Float64PtrToIntPtrWithCents(res)
assert.Equal(t, inInt, *outInt)
outInt2 := util.Float64ToInt64WithCents(*res)
assert.Equal(t, int64(inInt), outInt2)
})
}
}
func TestCurrencyConversionNil(t *testing.T) {
res := util.Int64PtrWithCentsToFloat64Ptr(nil)
assert.Nil(t, res)
res = util.IntPtrWithCentsToFloat64Ptr(nil)
assert.Nil(t, res)
res2 := util.Float64PtrToInt64PtrWithCents(nil)
assert.Nil(t, res2)
res3 := util.Float64PtrToIntPtrWithCents(nil)
assert.Nil(t, res3)
}