...
1 package gmeasure_test
2
3 import (
4 "time"
5
6 . "github.com/onsi/ginkgo/v2"
7 . "github.com/onsi/gomega"
8 "github.com/onsi/gomega/gmeasure"
9 )
10
11 var _ = Describe("Stats", func() {
12 var stats gmeasure.Stats
13
14 Describe("Stats representing values", func() {
15 BeforeEach(func() {
16 stats = gmeasure.Stats{
17 Type: gmeasure.StatsTypeValue,
18 ExperimentName: "My Test Experiment",
19 MeasurementName: "Sprockets",
20 Units: "widgets",
21 N: 100,
22 PrecisionBundle: gmeasure.Precision(2),
23 ValueBundle: map[gmeasure.Stat]float64{
24 gmeasure.StatMin: 17.48992,
25 gmeasure.StatMax: 293.4820,
26 gmeasure.StatMean: 187.3023,
27 gmeasure.StatMedian: 87.2235,
28 gmeasure.StatStdDev: 73.6394,
29 },
30 }
31 })
32
33 Describe("String()", func() {
34 It("returns a one-line summary", func() {
35 Ω(stats.String()).Should(Equal("17.49 < [87.22] | <187.30> ±73.64 < 293.48"))
36 })
37 })
38
39 Describe("ValueFor()", func() {
40 It("returns the value for the requested stat", func() {
41 Ω(stats.ValueFor(gmeasure.StatMin)).Should(Equal(17.48992))
42 Ω(stats.ValueFor(gmeasure.StatMean)).Should(Equal(187.3023))
43 })
44 })
45
46 Describe("FloatFor", func() {
47 It("returns the requested stat as a float", func() {
48 Ω(stats.FloatFor(gmeasure.StatMin)).Should(Equal(17.48992))
49 Ω(stats.FloatFor(gmeasure.StatMean)).Should(Equal(187.3023))
50 })
51 })
52
53 Describe("StringFor", func() {
54 It("returns the requested stat rendered with the configured precision", func() {
55 Ω(stats.StringFor(gmeasure.StatMin)).Should(Equal("17.49"))
56 Ω(stats.StringFor(gmeasure.StatMean)).Should(Equal("187.30"))
57 })
58 })
59 })
60
61 Describe("Stats representing durations", func() {
62 BeforeEach(func() {
63 stats = gmeasure.Stats{
64 Type: gmeasure.StatsTypeDuration,
65 ExperimentName: "My Test Experiment",
66 MeasurementName: "Runtime",
67 N: 100,
68 PrecisionBundle: gmeasure.Precision(time.Millisecond * 100),
69 DurationBundle: map[gmeasure.Stat]time.Duration{
70 gmeasure.StatMin: 17375 * time.Millisecond,
71 gmeasure.StatMax: 890321 * time.Millisecond,
72 gmeasure.StatMean: 328712 * time.Millisecond,
73 gmeasure.StatMedian: 552390 * time.Millisecond,
74 gmeasure.StatStdDev: 186259 * time.Millisecond,
75 },
76 }
77 })
78 Describe("String()", func() {
79 It("returns a one-line summary", func() {
80 Ω(stats.String()).Should(Equal("17.4s < [9m12.4s] | <5m28.7s> ±3m6.3s < 14m50.3s"))
81 })
82 })
83 Describe("DurationFor()", func() {
84 It("returns the duration for the requested stat", func() {
85 Ω(stats.DurationFor(gmeasure.StatMin)).Should(Equal(17375 * time.Millisecond))
86 Ω(stats.DurationFor(gmeasure.StatMean)).Should(Equal(328712 * time.Millisecond))
87 })
88 })
89
90 Describe("FloatFor", func() {
91 It("returns the float64 representation for the requested duration stat", func() {
92 Ω(stats.FloatFor(gmeasure.StatMin)).Should(Equal(float64(17375 * time.Millisecond)))
93 Ω(stats.FloatFor(gmeasure.StatMean)).Should(Equal(float64(328712 * time.Millisecond)))
94 })
95 })
96
97 Describe("StringFor", func() {
98 It("returns the requested stat rendered with the configured precision", func() {
99 Ω(stats.StringFor(gmeasure.StatMin)).Should(Equal("17.4s"))
100 Ω(stats.StringFor(gmeasure.StatMean)).Should(Equal("5m28.7s"))
101 })
102 })
103 })
104 })
105
View as plain text