本文整理匯總了Golang中tools/benchmark/metricsreporter.Counter.IncrementValue方法的典型用法代碼示例。如果您正苦於以下問題:Golang Counter.IncrementValue方法的具體用法?Golang Counter.IncrementValue怎麽用?Golang Counter.IncrementValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類tools/benchmark/metricsreporter.Counter
的用法示例。
在下文中一共展示了Counter.IncrementValue方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1:
BeforeEach(func() {
counter1 = metricsreporter.NewCounter("counter1")
counter2 = metricsreporter.NewCounter("counter2")
counters = []*metricsreporter.Counter{counter1, counter2}
})
It("reports the column names", func() {
Eventually(buffer).Should(gbytes.Say("Runtime, Sent, Received, Rate, PercentLoss, counter1, counter2"))
})
It("reports additional counter values", func() {
reporter.ReceivedCounter().IncrementValue()
reporter.SentCounter().IncrementValue()
counter1.IncrementValue()
counter2.IncrementValue()
counter2.IncrementValue()
Eventually(reporter.NumTicks, "20ms", "1ms").Should(BeEquivalentTo(1))
Eventually(buffer, 10).Should(gbytes.Say(fmt.Sprintf("%s, 1, 1, %.2f/s, 0.00%%, 1, 2", reporter.Duration(), reporter.Rate())))
})
It("reports individual counter average", func() {
reporter.SentCounter().IncrementValue()
reporter.SentCounter().IncrementValue()
reporter.ReceivedCounter().IncrementValue()
counter1.IncrementValue()
counter2.IncrementValue()
counter2.IncrementValue()
示例2:
Context("GetValue", func() {
It("returns its current value", func() {
Expect(counter.GetValue()).To(BeEquivalentTo(0))
})
})
Context("GetTotal", func() {
It("returns its current total", func() {
Expect(counter.GetTotal()).To(BeEquivalentTo(0))
})
})
Context("IncrementValue", func() {
It("increments the value", func() {
counter.IncrementValue()
Expect(counter.GetValue()).To(BeEquivalentTo(1))
})
})
Context("Reset", func() {
It("adds the current value to the total and resets the value to zero", func() {
counter.IncrementValue()
counter.IncrementValue()
counter.Reset()
Expect(counter.GetValue()).To(BeEquivalentTo(0))
Expect(counter.GetTotal()).To(BeEquivalentTo(2))
})
})