domingo, 13 de fevereiro de 2011

Fatorial

O que importa é passar no teste!
    def testFactorial
        assert_equal(120, factorial(5))
    end

    def factorial(input)
        case input
            when 5 : 5 * 4 * 3 * 2 * 1
            when 3 : 3 * 2 * 1
            when 0 : 1
            else raise "input cannot be negative"
        end
    end

Nenhum comentário:

Postar um comentário