Created
January 30, 2010 15:18
-
-
Save phillipoertel/290590 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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