Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failing test on non x86 architectures #103

Open
nileshpatra opened this issue Jun 25, 2021 · 1 comment
Open

Failing test on non x86 architectures #103

nileshpatra opened this issue Jun 25, 2021 · 1 comment

Comments

@nileshpatra
Copy link

nileshpatra commented Jun 25, 2021

Hi @schollz

Thanks for your work on progressbar :)
However, while running tests on !x86 architectures, one of the test fails -- in particular this one:

=== RUN   ExampleOptionSetRenderBlankState
--- FAIL: ExampleOptionSetRenderBlankState (0.00s)
got:
0% |          |  [0s:-1s]
want:
0% |          |  [0s:0s]

On investigating further, it seems that the value of rightBrac is turning out to be negative. On further investigation, it is found that the value of the averageRate variable is "0" for this particular test, and hence a division by 0 is happening there, which results in a +Inf, now the rest of the operations convert this into 0s on x86 and -1 on rest arches.

Here's a sample code for instance:

package main

import
	(
		"time"
		"fmt"
	);

func main() {
	var rate float64 = 0
	max := 10
	min := 0
	res:= (time.Duration((1 / rate)*(float64(max) - float64(min))) * time.Second).String()
	fmt.Println(res)
}

Output on x86: 0s
Output on arm64/other arches: -1s

For now, I've applied this patch to force a 0s value if rightBrac is 0s:

--- a/progressbar.go
+++ b/progressbar.go
@@ -730,6 +730,11 @@
 	if c.predictTime {
 		leftBrac = (time.Duration(time.Since(s.startTime).Seconds()) * time.Second).String()
 		rightBrac = (time.Duration((1/averageRate)*(float64(c.max)-float64(s.currentNum))) * time.Second).String()
+		zerosec, _ := time.ParseDuration("0s")
+		rightsec, _ := time.ParseDuration(rightBrac)
+		if rightsec.Seconds() < zerosec.Seconds() {
+			rightBrac = "0s"
+		}
 	}
 
 	if c.fullWidth && !c.ignoreLength {

But I admit this might not be the best way to get around it. Please consider fixing this

@schollz
Copy link
Owner

schollz commented Apr 14, 2022

Can you submit a PR to fix?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants