MCPcopy
hub / github.com/montanaflynn/stats / TestRound

Function TestRound

round_test.go:17–43  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

15}
16
17func TestRound(t *testing.T) {
18 for _, c := range []struct {
19 number float64
20 decimals int
21 result float64
22 }{
23 {0.1111, 1, 0.1},
24 {-0.1111, 2, -0.11},
25 {5.3253, 3, 5.325},
26 {5.3258, 3, 5.326},
27 {5.3253, 0, 5.0},
28 {5.55, 1, 5.6},
29 } {
30 m, err := stats.Round(c.number, c.decimals)
31 if err != nil {
32 t.Errorf("Returned an error")
33 }
34 if m != c.result {
35 t.Errorf("%.1f != %.1f", m, c.result)
36 }
37
38 }
39 _, err := stats.Round(math.NaN(), 2)
40 if err == nil {
41 t.Errorf("Round should error on NaN")
42 }
43}
44
45func BenchmarkRound(b *testing.B) {
46 for i := 0; i < b.N; i++ {

Callers

nothing calls this directly

Calls 1

RoundFunction · 0.92

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…