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

Function TestDecimal_ExtremeValues

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

Source from the content-addressed store, hash-verified

2243}
2244
2245func TestDecimal_ExtremeValues(t *testing.T) {
2246 // NOTE(vadim): this test takes pretty much forever
2247 if testing.Short() {
2248 t.Skip()
2249 }
2250
2251 // NOTE(vadim): Seriously, the numbers involved are so large that this
2252 // test will take way too long, so mark it as success if it takes over
2253 // 1 second. The way this test typically fails (integer overflow) is that
2254 // a wrong result appears quickly, so if it takes a long time then it is
2255 // probably working properly.
2256 // Why even bother testing this? Completeness, I guess. -Vadim
2257 const timeLimit = 1 * time.Second
2258 test := func(f func()) {
2259 c := make(chan bool)
2260 go func() {
2261 f()
2262 close(c)
2263 }()
2264 select {
2265 case <-c:
2266 case <-time.After(timeLimit):
2267 }
2268 }
2269
2270 test(func() {
2271 got := New(123, math.MinInt32).Floor()
2272 if !got.Equal(NewFromFloat(0)) {
2273 t.Errorf("Error: got %s, expected 0", got)
2274 }
2275 })
2276 test(func() {
2277 got := New(123, math.MinInt32).Ceil()
2278 if !got.Equal(NewFromFloat(1)) {
2279 t.Errorf("Error: got %s, expected 1", got)
2280 }
2281 })
2282 test(func() {
2283 got := New(123, math.MinInt32).Rat().FloatString(10)
2284 expected := "0.0000000000"
2285 if got != expected {
2286 t.Errorf("Error: got %s, expected %s", got, expected)
2287 }
2288 })
2289}
2290
2291func TestIntPart(t *testing.T) {
2292 for _, testCase := range []struct {

Callers

nothing calls this directly

Calls 6

NewFunction · 0.85
NewFromFloatFunction · 0.85
FloorMethod · 0.80
EqualMethod · 0.80
CeilMethod · 0.80
RatMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…