MCPcopy
hub / github.com/tdewolff/minify / TestDecimalRandom

Function TestDecimalRandom

common_test.go:314–331  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

312}
313
314func TestDecimalRandom(t *testing.T) {
315 N := int(1e4)
316 if testing.Short() {
317 N = 0
318 }
319 for i := 0; i < N; i++ {
320 b := RandNumBytes(false)
321 f, _ := strconv.ParseFloat(string(b), 64)
322
323 b2 := make([]byte, len(b))
324 copy(b2, b)
325 b2 = Decimal(b2, -1)
326 f2, _ := strconv.ParseFloat(string(b2), 64)
327 if math.Abs(f-f2) > 1e-6 {
328 fmt.Println("Bad:", f, "!=", f2, "in", string(b), "to", string(b2))
329 }
330 }
331}
332
333func TestNumberRandom(t *testing.T) {
334 N := int(1e4)

Callers

nothing calls this directly

Calls 5

RandNumBytesFunction · 0.85
lenFunction · 0.85
DecimalFunction · 0.85
stringFunction · 0.50
copyFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…