Skip to content

Instantly share code, notes, and snippets.

@huezoaa
Created January 18, 2015 20:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save huezoaa/824cc0e9fb97099f511e to your computer and use it in GitHub Desktop.
Save huezoaa/824cc0e9fb97099f511e to your computer and use it in GitHub Desktop.
Max Refactor
def max(num1, num2, *num)
num1 > num2 ? num1 : num2
end
def test # Assume all entries are numeric
p max(1,9,3,5,99,23,115,32,922,3983,38374,28474,10937134) == 9
p max(1,2) == 2 # (Fixnum, Fixnum)
p max(2,1) == 2 # (Fixnum, Fixnum)
p max(0.1, 0.2) == 0.2 # (Float, Float)
p max(0.2, 0.1) == 0.2 # (Float, Float)
p max(1,1.1) == 1.1 # (Fixnum, Float)
p max(1.1,1) == 1.1 # ==> num1 num1 > num2 (Float, Fixnum)
p max(0.99999991, 0.99993999999999999) == 0.99999991 # ==> 0.99999991 Float, Float, Lots of decimal places
p max(-1, 1) == 1 # ==> 1 Fixnum, Fixnum, Negative, Positive
p max(2, -2) == 2 # ==> 2 Fixnum, Fixnum, Positve, Negative
p max(1,1) == 1 # ==> 1 Fixnum, Fixnum, Equal values positive
p max(-2, -2) == -2 # ==> -2 Fixnum, Fixnum, Equal values negative
p max(10, 20) == 20 # ==> 20 Fixnum, Fixnum, Positive, Positive
p max(-10, -20) == -10 # ==> -10 Fixnum, Fixnum, Negative, Negative
p max(-99.99, 99.99) == 99.99 # ==> 99.99 Float, Float, Negative, Positive
p max(99.99,-199) == 99.99 # ==> 99.99 Float, Float, Positive, Negative
p max(199.99,199.99) == 199.99 # ==> 199.99Float, Float, Equal values positve
p max(-199.99,-199.99) == -199.99 # Float, Float, Equal values negative
p max(107.90, 107.90) == 107.90 # Float, Float, Positive, Positive
p max(-3.00, -3.00) == -3.00 # Float, Float, Negative, Negative
p max(0,0) == 0 # Fixnum, Fixnum, 0, 0
p max(0,0.0) == 0 # Fixnum, Float, 0, 0.0 --> interesting result
p max(0.0,0) == 0 # Float, Fixnum, 0.0, 0 --> result is different than above!
p max(0.0, 0.0) == 0.0 # Float, Float, 0.0, 0.0
end
test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment