-
Notifications
You must be signed in to change notification settings - Fork 375
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
[core] add metrics testing #81
Conversation
@metrics[key] = value | ||
rescue StandardError => e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that a cast will raise an ArgumentError
.
A cleaner way would be to check if value.is_a?(Integer) || value.is_a?(Float)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if nil
is passed it will be a TypeError
:
irb(main):001:0> Float(nil)
TypeError: can't convert nil into Float
from (irb):1:in `Float'
from (irb):1
from .../versions/2.3.1/bin/irb:11:in `<main>'
The reason to use the Float(value)
is that a string may be converted to float
, as we're doing in the Python implementation. I think it was already discussed before about why we should at least try to make it work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok then.
assert_equal(expected, h[:metrics]) | ||
end | ||
|
||
def test_invalid_metrics |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
What it does
set_metric
for valid and invalid valuesvalue
used inset_metric
is stored asfloat