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

feat: add Convert #33

Closed
wants to merge 1 commit into from
Closed

feat: add Convert #33

wants to merge 1 commit into from

Conversation

ccoVeille
Copy link
Owner

@ccoVeille ccoVeille commented Sep 18, 2024

This PR improves the issues @ldemailly had with its implementation

Fixes #21

This PR improves the issues @ldemailly had with its implementation
Copy link

codecov bot commented Sep 18, 2024

Codecov Report

Attention: Patch coverage is 50.00000% with 35 lines in your changes missing coverage. Please review.

Project coverage is 80.97%. Comparing base (390ade6) to head (8749dd5).
Report is 18 commits behind head on main.

Files with missing lines Patch % Lines
generics.go 50.00% 34 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##              main      #33       +/-   ##
============================================
- Coverage   100.00%   80.97%   -19.03%     
============================================
  Files            3        4        +1     
  Lines          114      184       +70     
============================================
+ Hits           114      149       +35     
- Misses           0       34       +34     
- Partials         0        1        +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ccoVeille
Copy link
Owner Author

draft as the coverage is still low while I added so a lot of tests... I quit for the day

@ldemailly
Copy link
Collaborator

ldemailly commented Sep 19, 2024

Can you share which of the test would fail with my version?

Also you shouldn't math.Trunc() inside convert. Doing

f := 1.5
v, err := Convert[int](f)

should error as it definitively does lose precision

That's why my version has Truncate() and Round() but also let you check "direct" floats if the expectations is that they are supposed to have already been made into integers

Edit: see TestNonIntegerFloat in fortio/safecast#8

@ccoVeille
Copy link
Owner Author

Replaced by #55

@ccoVeille ccoVeille closed this Dec 14, 2024
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

Successfully merging this pull request may close these issues.

Consider adding Convert function handling all types
2 participants