Fixed panic, added some tests

This commit is contained in:
sm
2015-10-31 16:16:27 -07:00
parent 1c4f1a6f95
commit fc1f5ce2bc
2 changed files with 63 additions and 25 deletions
+7 -4
View File
@@ -133,7 +133,7 @@ func (b *BPS) HumanRate() string {
// Sparkline returns a human-friendly sprakline of history
func (b *BPS) Sparkline(count int) string {
if count > len(b.buckets) {
if count <= 0 || count > len(b.buckets) {
return "bucket count inappropriate"
}
sparks := []string{"▁", "▂", "▃", "▄", "▅", "▆", "▇", "█"}
@@ -147,9 +147,12 @@ func (b *BPS) Sparkline(count int) string {
// find max
for i := 0; i < len(b.buckets); i++ {
cur = b.buckets[i]
if cur > max {
max = cur
cur += b.buckets[i]
if i%bucketsPer == 0 {
if cur > max {
max = cur
}
cur = 0
}
}