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

Support other units #1

Merged
merged 9 commits into from
Jan 3, 2024
Merged

Support other units #1

merged 9 commits into from
Jan 3, 2024

Conversation

NelsonVides
Copy link
Collaborator

Also solves an issue where the penalisation added to the last_update element was in millisecond units unconverted to the correctly used native.

@codecov-commenter
Copy link

codecov-commenter commented Jan 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (5f28665) 72.72% compared to head (251fbf4) 84.37%.

Additional details and impacted files
@@             Coverage Diff             @@
##             main       #1       +/-   ##
===========================================
+ Coverage   72.72%   84.37%   +11.64%     
===========================================
  Files           2        2               
  Lines          77       96       +19     
===========================================
+ Hits           56       81       +25     
+ Misses         21       15        -6     

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

Copy link
Member

@chrzaszcz chrzaszcz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a few comments.

src/opuntia.erl Outdated Show resolved Hide resolved
src/opuntia.erl Outdated Show resolved Hide resolved
src/opuntia.erl Outdated Show resolved Hide resolved
NewHistory = [{ConsumeNow, DelayMs, NewShaper} | History],
NewDelay = AccumulatedDelay + DelayMs,
NewToConsume = TokensLeft - ConsumeNow,
case is_integer(DelayMs) andalso DelayMs >= 0 of
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type of DelayMs should be non_neg_integer(), so why would you expect anything else?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm checking in tests that that is actually the case, because the type definition might end up failing, disadvantage of dynamic typing 🥲

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it looks like we accept a bad result (not matching the type spec), because the test doesn't fail in the false clause.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... but we stop running and will fail later. Actually, I've just noticed here I'm returning a 4-tuple, which will fail with an error. I'll return a value that will always fall outside of the conditioned range instead.

test/opuntia_SUITE.erl Outdated Show resolved Hide resolved
Copy link
Member

@chrzaszcz chrzaszcz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good in general. I appreciate splitting the logic. I added some minor comments. I haven't checked all the maths in detail, because it is checked in test cases.

src/opuntia.erl Outdated Show resolved Hide resolved
src/opuntia.erl Outdated Show resolved Hide resolved
NewHistory = [{ConsumeNow, DelayMs, NewShaper} | History],
NewDelay = AccumulatedDelay + DelayMs,
NewToConsume = TokensLeft - ConsumeNow,
case is_integer(DelayMs) andalso DelayMs >= 0 of
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it looks like we accept a bad result (not matching the type spec), because the test doesn't fail in the false clause.

src/opuntia.erl Outdated Show resolved Hide resolved
src/opuntia.erl Outdated Show resolved Hide resolved
src/opuntia.erl Outdated Show resolved Hide resolved
Copy link
Member

@chrzaszcz chrzaszcz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the corrections, it all looks good to me now.

@chrzaszcz chrzaszcz merged commit 68a85b9 into main Jan 3, 2024
3 checks passed
@chrzaszcz chrzaszcz deleted the support_other_units branch January 3, 2024 16:20
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.

None yet

3 participants