Change Humanzie() -> String()

This commit is contained in:
Daniel Bornkessel 2012-12-19 11:10:09 +01:00
parent 628071f203
commit 644d89de15
10 changed files with 31 additions and 31 deletions

View File

@ -65,7 +65,7 @@ func (b *AccumulatingBucket) Add(value float64) {
heap.Push(&b.elements, &v)
}
func (b *AccumulatingBucket) Humanize() string {
func (b *AccumulatingBucket) String() string {
b.mutex.RLock()
defer b.mutex.RUnlock()

View File

@ -27,25 +27,25 @@ func (s *S) TestAccumulatingBucketBuilderWithEvictOldest(c *C) {
var b Bucket = bb()
c.Assert(b, Not(IsNil))
c.Check(b.Humanize(), Equals, "[AccumulatingBucket with 0 elements and 5 capacity] { }")
c.Check(b.String(), Equals, "[AccumulatingBucket with 0 elements and 5 capacity] { }")
b.Add(1)
c.Check(b.Humanize(), Equals, "[AccumulatingBucket with 1 elements and 5 capacity] { 1.000000, }")
c.Check(b.String(), Equals, "[AccumulatingBucket with 1 elements and 5 capacity] { 1.000000, }")
b.Add(2)
c.Check(b.Humanize(), Equals, "[AccumulatingBucket with 2 elements and 5 capacity] { 1.000000, 2.000000, }")
c.Check(b.String(), Equals, "[AccumulatingBucket with 2 elements and 5 capacity] { 1.000000, 2.000000, }")
b.Add(3)
c.Check(b.Humanize(), Equals, "[AccumulatingBucket with 3 elements and 5 capacity] { 1.000000, 2.000000, 3.000000, }")
c.Check(b.String(), Equals, "[AccumulatingBucket with 3 elements and 5 capacity] { 1.000000, 2.000000, 3.000000, }")
b.Add(4)
c.Check(b.Humanize(), Equals, "[AccumulatingBucket with 4 elements and 5 capacity] { 1.000000, 2.000000, 3.000000, 4.000000, }")
c.Check(b.String(), Equals, "[AccumulatingBucket with 4 elements and 5 capacity] { 1.000000, 2.000000, 3.000000, 4.000000, }")
b.Add(5)
c.Check(b.Humanize(), Equals, "[AccumulatingBucket with 5 elements and 5 capacity] { 1.000000, 2.000000, 3.000000, 4.000000, 5.000000, }")
c.Check(b.String(), Equals, "[AccumulatingBucket with 5 elements and 5 capacity] { 1.000000, 2.000000, 3.000000, 4.000000, 5.000000, }")
b.Add(6)
c.Check(b.Humanize(), Equals, "[AccumulatingBucket with 3 elements and 5 capacity] { 4.000000, 5.000000, 6.000000, }")
c.Check(b.String(), Equals, "[AccumulatingBucket with 3 elements and 5 capacity] { 4.000000, 5.000000, 6.000000, }")
var bucket Bucket = b
@ -65,25 +65,25 @@ func (s *S) TestAccumulatingBucketBuilderWithEvictAndReplaceWithAverage(c *C) {
c.Assert(b, Not(IsNil))
c.Check(b.Humanize(), Equals, "[AccumulatingBucket with 0 elements and 5 capacity] { }")
c.Check(b.String(), Equals, "[AccumulatingBucket with 0 elements and 5 capacity] { }")
b.Add(1)
c.Check(b.Humanize(), Equals, "[AccumulatingBucket with 1 elements and 5 capacity] { 1.000000, }")
c.Check(b.String(), Equals, "[AccumulatingBucket with 1 elements and 5 capacity] { 1.000000, }")
b.Add(2)
c.Check(b.Humanize(), Equals, "[AccumulatingBucket with 2 elements and 5 capacity] { 1.000000, 2.000000, }")
c.Check(b.String(), Equals, "[AccumulatingBucket with 2 elements and 5 capacity] { 1.000000, 2.000000, }")
b.Add(3)
c.Check(b.Humanize(), Equals, "[AccumulatingBucket with 3 elements and 5 capacity] { 1.000000, 2.000000, 3.000000, }")
c.Check(b.String(), Equals, "[AccumulatingBucket with 3 elements and 5 capacity] { 1.000000, 2.000000, 3.000000, }")
b.Add(4)
c.Check(b.Humanize(), Equals, "[AccumulatingBucket with 4 elements and 5 capacity] { 1.000000, 2.000000, 3.000000, 4.000000, }")
c.Check(b.String(), Equals, "[AccumulatingBucket with 4 elements and 5 capacity] { 1.000000, 2.000000, 3.000000, 4.000000, }")
b.Add(5)
c.Check(b.Humanize(), Equals, "[AccumulatingBucket with 5 elements and 5 capacity] { 1.000000, 2.000000, 3.000000, 4.000000, 5.000000, }")
c.Check(b.String(), Equals, "[AccumulatingBucket with 5 elements and 5 capacity] { 1.000000, 2.000000, 3.000000, 4.000000, 5.000000, }")
b.Add(6)
c.Check(b.Humanize(), Equals, "[AccumulatingBucket with 4 elements and 5 capacity] { 4.000000, 5.000000, 2.000000, 6.000000, }")
c.Check(b.String(), Equals, "[AccumulatingBucket with 4 elements and 5 capacity] { 4.000000, 5.000000, 2.000000, 6.000000, }")
}
func (s *S) TestAccumulatingBucket(c *C) {

View File

@ -32,7 +32,7 @@ type Bucket interface {
/*
Provide a humanized representation hereof.
*/
Humanize() string
String() string
/*
Provide a count of observations throughout the bucket's lifetime.
*/

View File

@ -24,7 +24,7 @@ type GaugeMetric struct {
mutex sync.RWMutex
}
func (metric *GaugeMetric) Humanize() string {
func (metric *GaugeMetric) String() string {
formatString := "[GaugeMetric; value=%f]"
metric.mutex.RLock()

View File

@ -19,9 +19,9 @@ func (s *S) TestCreate(c *C) {
c.Check(m.Get(), Equals, 1.0)
}
func (s *S) TestHumanize(c *C) {
func (s *S) TestString(c *C) {
m := GaugeMetric{value: 2.0}
c.Check(m.Humanize(), Equals, "[GaugeMetric; value=2.000000]")
c.Check(m.String(), Equals, "[GaugeMetric; value=2.000000]")
}
func (s *S) TestSet(c *C) {
@ -38,7 +38,7 @@ func (s *S) TestIncrementBy(c *C) {
m.IncrementBy(1.5)
c.Check(m.Get(), Equals, 2.5)
c.Check(m.Humanize(), Equals, "[GaugeMetric; value=2.500000]")
c.Check(m.String(), Equals, "[GaugeMetric; value=2.500000]")
}
func (s *S) TestIncrement(c *C) {
@ -47,7 +47,7 @@ func (s *S) TestIncrement(c *C) {
m.Increment()
c.Check(m.Get(), Equals, 2.0)
c.Check(m.Humanize(), Equals, "[GaugeMetric; value=2.000000]")
c.Check(m.String(), Equals, "[GaugeMetric; value=2.000000]")
}
func (s *S) TestDecrementBy(c *C) {
@ -56,7 +56,7 @@ func (s *S) TestDecrementBy(c *C) {
m.DecrementBy(1.0)
c.Check(m.Get(), Equals, 0.0)
c.Check(m.Humanize(), Equals, "[GaugeMetric; value=0.000000]")
c.Check(m.String(), Equals, "[GaugeMetric; value=0.000000]")
}
func (s *S) TestDecrement(c *C) {
@ -65,7 +65,7 @@ func (s *S) TestDecrement(c *C) {
m.Decrement()
c.Check(m.Get(), Equals, 0.0)
c.Check(m.Humanize(), Equals, "[GaugeMetric; value=0.000000]")
c.Check(m.String(), Equals, "[GaugeMetric; value=0.000000]")
}
func (s *S) TestGaugeMetricMarshallable(c *C) {

View File

@ -106,13 +106,13 @@ func (h *Histogram) Add(value float64) {
h.buckets[lastIndex].Add(value)
}
func (h *Histogram) Humanize() string {
func (h *Histogram) String() string {
stringBuffer := bytes.NewBufferString("")
stringBuffer.WriteString("[Histogram { ")
for i, bucketStart := range h.bucketStarts {
bucket := h.buckets[i]
stringBuffer.WriteString(fmt.Sprintf("[%f, inf) = %s, ", bucketStart, bucket.Humanize()))
stringBuffer.WriteString(fmt.Sprintf("[%f, inf) = %s, ", bucketStart, bucket.String()))
}
stringBuffer.WriteString("}]")

View File

@ -53,11 +53,11 @@ func (s *S) TestCreateHistogram(c *C) {
c.Assert(h, Not(IsNil))
c.Check(h.Humanize(), Equals, "[Histogram { [0.000000, inf) = [TallyingBucket (Empty)], [2.000000, inf) = [TallyingBucket (Empty)], [4.000000, inf) = [TallyingBucket (Empty)], [6.000000, inf) = [TallyingBucket (Empty)], [8.000000, inf) = [TallyingBucket (Empty)], }]")
c.Check(h.String(), Equals, "[Histogram { [0.000000, inf) = [TallyingBucket (Empty)], [2.000000, inf) = [TallyingBucket (Empty)], [4.000000, inf) = [TallyingBucket (Empty)], [6.000000, inf) = [TallyingBucket (Empty)], [8.000000, inf) = [TallyingBucket (Empty)], }]")
h.Add(1)
c.Check(h.Humanize(), Equals, "[Histogram { [0.000000, inf) = [TallyingBucket (1.000000, 1.000000); 1 items], [2.000000, inf) = [TallyingBucket (Empty)], [4.000000, inf) = [TallyingBucket (Empty)], [6.000000, inf) = [TallyingBucket (Empty)], [8.000000, inf) = [TallyingBucket (Empty)], }]")
c.Check(h.String(), Equals, "[Histogram { [0.000000, inf) = [TallyingBucket (1.000000, 1.000000); 1 items], [2.000000, inf) = [TallyingBucket (Empty)], [4.000000, inf) = [TallyingBucket (Empty)], [6.000000, inf) = [TallyingBucket (Empty)], [8.000000, inf) = [TallyingBucket (Empty)], }]")
}
func (s *S) TestBucketForPercentile(c *C) {

View File

@ -15,7 +15,7 @@ type Metric interface {
/*
Produce a human-consumable representation of the metric.
*/
Humanize() string
String() string
/*
Produce a JSON-consumable representation of the metric.
*/

View File

@ -104,7 +104,7 @@ func (b *TallyingBucket) Add(value float64) {
b.largestObserved = math.Max(value, b.largestObserved)
}
func (b *TallyingBucket) Humanize() string {
func (b *TallyingBucket) String() string {
b.mutex.RLock()
defer b.mutex.RUnlock()

View File

@ -45,14 +45,14 @@ func (s *S) TestTallyingBucketBuilder(c *C) {
c.Assert(bucket, Not(IsNil))
}
func (s *S) TestTallyingBucketHumanize(c *C) {
func (s *S) TestTallyingBucketString(c *C) {
bucket := TallyingBucket{
observations: 3,
smallestObserved: 2.0,
largestObserved: 5.5,
}
c.Check(bucket.Humanize(), Equals, "[TallyingBucket (2.000000, 5.500000); 3 items]")
c.Check(bucket.String(), Equals, "[TallyingBucket (2.000000, 5.500000); 3 items]")
}
func (s *S) TestTallyingBucketAdd(c *C) {