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

Circle area Testing Errorf - float64 #237

Closed
erni93 opened this issue Sep 6, 2019 · 1 comment
Closed

Circle area Testing Errorf - float64 #237

erni93 opened this issue Sep 6, 2019 · 1 comment

Comments

@erni93
Copy link
Contributor

erni93 commented Sep 6, 2019

About this page, https://github.com/quii/learn-go-with-tests/blob/master/structs-methods-and-interfaces.md

I see a different ways to show the circle area value, in some parts with %f and %.2f

In any case, it won't give you too much info to see why the test fails

Example

With a circle with area 5, I think should be 78.539816339745 (Doing my self or using an online calculator), with got %f want %f it shows

got 78.539816 want 78.539816

But, if I change it to %g

got 78.53981633974483 want 78.539816339745

Ok, perfect, set want to 78.53981633974483

https://golang.org/pkg/fmt/

For floating-point values, width sets the minimum width of the field and precision sets the number of places after the decimal, if appropriate, except that for %g/%G precision sets the maximum number of significant digits (trailing zeros are removed)

Another approach could be round the unit test result, but this can be a bit dangerous

@quii
Copy link
Owner

quii commented Sep 10, 2019

This seems like a good improvement - do you want to raise a PR so you get credit for the change?

erni93 added a commit to erni93/learn-go-with-tests that referenced this issue Sep 10, 2019
@quii quii closed this as completed Jan 30, 2020
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