Skip to content

Instantly share code, notes, and snippets.

@phillipoertel
Created January 30, 2010 15:18
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 phillipoertel/290590 to your computer and use it in GitHub Desktop.
Save phillipoertel/290590 to your computer and use it in GitHub Desktop.
require 'test/unit'
def factorial(max)
(1..max).inject(1) { |sum, current| sum *= current; sum }
end
class FactorialTest < Test::Unit::TestCase
def test_factorial_0_is_1
assert_equal 1, factorial(0)
end
def test_factorial_1_is_1
assert_equal 1, factorial(1)
end
def test_factorial_2_is_2
assert_equal 2, factorial(2)
end
def test_factorial_3_is_6
assert_equal 6, factorial(3)
end
def test_factorial_4_is_24
assert_equal 24, factorial(4)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment