Skip to content

Commit

Permalink
Merge 89ad6e2 into a06b0e8
Browse files Browse the repository at this point in the history
  • Loading branch information
jedib0t committed Sep 13, 2018
2 parents a06b0e8 + 89ad6e2 commit 9548300
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
7 changes: 5 additions & 2 deletions progress/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ func (t *Tracker) ETA() time.Duration {
return t.ExpectedDuration - timeTaken
}

pDone := t.PercentDone()
pDone := int64(t.PercentDone())
if pDone == 0 {
return time.Duration(0)
}
return time.Duration((int64(timeTaken) / int64(pDone)) * int64(100-pDone))
return time.Duration((int64(timeTaken) / pDone) * (100 - pDone))
}

// Increment updates the current value of the task being tracked.
Expand Down Expand Up @@ -66,6 +66,9 @@ func (t *Tracker) MarkAsDone() {

// PercentDone returns the currently completed percentage value.
func (t *Tracker) PercentDone() float64 {
if t.Total == 0 {
return 0
}
return float64(t.value) * 100.0 / float64(t.Total)
}

Expand Down
6 changes: 5 additions & 1 deletion progress/tracker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ func TestTracker_ETA(t *testing.T) {
timeDelay := timeDelayUnit * 25

tracker := Tracker{Total: 100}
assert.Equal(t, time.Duration(0), tracker.ETA())
tracker.start()
assert.Equal(t, time.Duration(0), tracker.ETA())
time.Sleep(timeDelay)
Expand Down Expand Up @@ -65,7 +66,10 @@ func TestTracker_MarkAsDone(t *testing.T) {
}

func TestTracker_PercentDone(t *testing.T) {
tracker := Tracker{Total: 100}
tracker := Tracker{}
assert.Equal(t, 0.00, tracker.PercentDone())

tracker.Total = 100
assert.Equal(t, 0.00, tracker.PercentDone())

for idx := 1; idx <= 100; idx++ {
Expand Down

0 comments on commit 9548300

Please sign in to comment.