Fixed panic, added some tests
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user