Skip to content

Commit 527d6f1

Browse files
committed
Commit felhix#1
1 parent 100d6f0 commit 527d6f1

4 files changed

Lines changed: 76 additions & 11 deletions

File tree

lib/00_hello.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
def hello
2-
2+
return "Hello!"
33
end
44

55
def greet(name)
6-
6+
return "Hello, #{name}!"
77
end

lib/01_temperature.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Dans la spec : chaque "describe" va exécuter une série de méthodes tests
2+
# Dans le .rb : chaque def répond à une série de tests
3+
4+
def ftoc(a)
5+
temp_to_C = (a.to_f - 32) * 5/9
6+
return temp_to_C.to_f
7+
end
8+
9+
def ctof(a)
10+
temp_to_F = (a.to_f * 9/5) + 32
11+
return temp_to_F.to_f
12+
end

lib/02_calculator.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
2+
def add(a,b)
3+
return a + b
4+
end
5+
6+
def subtract(a,b)
7+
subtraction = a - b
8+
return subtraction
9+
end
10+
11+
def sum(tab)
12+
my_sum = tab.sum
13+
return my_sum
14+
end
15+
16+
def multiply(a,b)
17+
multiplication = a * b
18+
return multiplication
19+
end
20+
21+
def power(a)
22+
powered = a ** a
23+
return powered
24+
end
25+
26+
def factorial(a)
27+
factorial_of = 1
28+
(1..a).each do |counter|
29+
factorial_of = factorial_of * counter
30+
# return factorial Le return fait sortir de la boucle /!\
31+
end
32+
return factorial_of
33+
end

spec/02_calculator_spec.rb

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,23 +47,43 @@
4747
expect(multiply(3, 4)).to eq(12)
4848
end
4949

50-
it "multiplies two other numbers"
50+
it "multiplies two other numbers" do
5151
# one other test here, don't forget do end ;)
52+
expect(multiply(5, 10)).to eq(50)
53+
end
5254

53-
it "multiplies two other numbers, one of them being 0"
55+
it "multiplies two other numbers, one of them being 0" do
5456
# one last test, with 0 in it
55-
57+
expect(multiply(71, 0)).to eq(0)
58+
end
5659
end
5760

5861
describe "#power" do
59-
it "raises one number to the power of another number"
62+
it "raises one number to the power of another number" do
63+
expect(power(2)).to eq(4)
64+
end
6065
end
6166

6267
# http://en.wikipedia.org/wiki/Factorial
6368
describe "#factorial" do
64-
it "computes the factorial of 0"
65-
it "computes the factorial of 1"
66-
it "computes the factorial of 2"
67-
it "computes the factorial of 5"
68-
it "computes the factorial of 10"
69+
it "computes the factorial of 0" do
70+
expect(factorial(0)).to eq(0)
71+
end
72+
73+
it "computes the factorial of 1" do
74+
expect(factorial(1).to eq(1))
75+
end
76+
77+
it "computes the factorial of 2" do
78+
expect(factorial(2).to eq(2))
79+
end
80+
81+
it "computes the factorial of 5" do
82+
expect(factorial(5).to eq(120))
83+
end
84+
85+
it "computes the factorial of 10" do
86+
expect(factorial(10).to eq(3628800))
87+
end
88+
6989
end

0 commit comments

Comments
 (0)