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

(PUP-4698) Change fqdn_rand's return type to Integer #4020

Merged

Conversation

hlindberg
Copy link
Contributor

Before this, fqdn_rand always returned a String. That is not the best
choice for a numeric value now that the evaluator is aware of different
data types as comparissons will typically be wrong (since '2' > '19'
when compared leicographically).

This fix adds a utility method that returns an integer version while the
old utility method producing a string is retained for those that use
Puppet as an API. The function now uses the integer version of this
utility method.

A test is added that asserts that an Integer is produced.

At some point it would be beneficial to reimplement the function using
the 4.x function API as it will simply raise a generic error if given
input of the wrong type. It will also magically change a floating point
input value to integer.

Before this, fqdn_rand always returned a String. That is not the best
choice for a numeric value now that the evaluator is aware of different
data types as comparissons will typically be wrong (since '2' > '19'
when compared leicographically).

This fix adds a utility method that returns an integer version while the
old utility method producing a string is retained for those that use
Puppet as an API. The function now uses the integer version of this
utility method.

A test is added that asserts that an Integer is produced.

At some point it would be beneficial to reimplement the function using
the 4.x function API as it will simply raise a generic error if given
input of the wrong type. It will also magically change a floating point
input value to integer.
@hlindberg
Copy link
Contributor Author

App Veyor failing with known issues regarding rdoc

@puppetcla
Copy link

CLA signed by all contributors.

it "returns an integer" do
expect(fqdn_rand(3)).to satisfy {|n| n.is_a?(Integer) }
end

it "provides a random number strictly less than the given max" do
expect(fqdn_rand(3)).to satisfy {|n| n.to_i < 3 }
Copy link

Choose a reason for hiding this comment

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

can the to_i go away now?

@kylog
Copy link

kylog commented Jun 10, 2015

Other than that one nit in the spec, I'm 👍

@kylog
Copy link

kylog commented Jun 10, 2015

And appveyor failures are the usual rdoc ones. Known bogo-failure.



it "returns an integer" do
expect(fqdn_rand(3)).to satisfy {|n| n.is_a?(Integer) }
Copy link
Contributor

Choose a reason for hiding this comment

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

Simpler as expect(fqdn_rand(3)).to be_a(Integer)

@hlindberg
Copy link
Contributor Author

ok - two nits - will update

* no need to convert to integer in test asserts since fqdn now returns
and integer

* simplified assert using be_an instead of satisfies
thallgren added a commit that referenced this pull request Jun 11, 2015
…n-numric

(PUP-4698) Change fqdn_rand's return type to Integer
@thallgren thallgren merged commit d4a2851 into puppetlabs:stable Jun 11, 2015
@hlindberg hlindberg deleted the PUP-4698_make-fqdn-rand-return-numric branch September 16, 2017 08:39
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

4 participants