-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfactorial.rb
53 lines (39 loc) · 869 Bytes
/
factorial.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
class Factorial
def initialize(num)
@num = num
end
def process
recursion(@num)
end
def recursion(a)
return 1 if [0,1].include?(a)
recursion(a-1) * a
end
end
require 'minitest/autorun'
class FactorialTest < Minitest::Unit::TestCase
def test_process_1
assert_equal 1, Factorial.new(0).process
end
def test_process_2
assert_equal 1, Factorial.new(1).process
end
def test_process_3
assert_equal 2, Factorial.new(2).process
end
def test_process_4
assert_equal 6, Factorial.new(3).process
end
def test_process_5
assert_equal 24, Factorial.new(4).process
end
def test_process_6
assert_equal 120, Factorial.new(5).process
end
def test_process_7
assert_equal 40320, Factorial.new(8).process
end
def test_process_8
assert_equal 479001600, Factorial.new(12).process
end
end