MCPcopy
hub / github.com/shopspring/decimal / TestDecimal_rescale

Function TestDecimal_rescale

decimal_test.go:945–980  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

943}
944
945func TestDecimal_rescale(t *testing.T) {
946 type Inp struct {
947 int int64
948 exp int32
949 rescale int32
950 }
951 tests := map[Inp]string{
952 Inp{1234, -3, -5}: "1.234",
953 Inp{1234, -3, 0}: "1",
954 Inp{1234, 3, 0}: "1234000",
955 Inp{1234, -4, -4}: "0.1234",
956 }
957
958 // add negatives
959 for p, s := range tests {
960 if p.int > 0 {
961 tests[Inp{-p.int, p.exp, p.rescale}] = "-" + s
962 }
963 }
964
965 for input, s := range tests {
966 d := New(input.int, input.exp).rescale(input.rescale)
967
968 if d.String() != s {
969 t.Errorf("expected %s, got %s (%s, %d)",
970 s, d.String(),
971 d.value.String(), d.exp)
972 }
973
974 // test StringScaled
975 s2 := New(input.int, input.exp).StringScaled(input.rescale)
976 if s2 != s {
977 t.Errorf("expected %s, got %s", s, s2)
978 }
979 }
980}
981
982func TestDecimal_Floor(t *testing.T) {
983 assertFloor := func(input, expected Decimal) {

Callers

nothing calls this directly

Calls 4

NewFunction · 0.85
rescaleMethod · 0.80
StringScaledMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…