diff options
-rw-r--r-- | README.md | 4 | ||||
-rw-r--r-- | functions/round.pp | 9 | ||||
-rwxr-xr-x | spec/functions/round_spec.rb | 11 |
3 files changed, 24 insertions, 0 deletions
@@ -1509,6 +1509,10 @@ For example, `reject(['aaa','bbb','ccc','aaaddd'], 'aaa')` returns ['bbb','ccc'] Reverses the order of a string or array. +#### `stdlib::round` + + Rounds a number to the nearest integer + *Type*: rvalue. #### `rstrip` diff --git a/functions/round.pp b/functions/round.pp new file mode 100644 index 0000000..6bad92d --- /dev/null +++ b/functions/round.pp @@ -0,0 +1,9 @@ +function stdlib::round( + Numeric $input, +) { + if $input >= 0 { + Integer( $input + 0.5 ) + } else { + Integer( $input - 0.5 ) + } +} diff --git a/spec/functions/round_spec.rb b/spec/functions/round_spec.rb new file mode 100755 index 0000000..5aa801c --- /dev/null +++ b/spec/functions/round_spec.rb @@ -0,0 +1,11 @@ +require 'spec_helper' + +describe 'stdlib::round' do + it { is_expected.not_to eq(nil) } + it { is_expected.to run.with_params(34.3).and_return(34) } + it { is_expected.to run.with_params(-34.3).and_return(-34) } + it { is_expected.to run.with_params(34.5).and_return(35) } + it { is_expected.to run.with_params(-34.5).and_return(-35) } + it { is_expected.to run.with_params(34.7).and_return(35) } + it { is_expected.to run.with_params(-34.7).and_return(-35) } +end |