From 3b62fecf03251a346c301011cb7ea184989a6886 Mon Sep 17 00:00:00 2001 From: Robert Bright Date: Mon, 9 Apr 2018 21:21:36 +0100 Subject: [PATCH 1/5] Rename README.md to instructions.md --- README.md => instructions.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename README.md => instructions.md (100%) diff --git a/README.md b/instructions.md similarity index 100% rename from README.md rename to instructions.md From f92da14f09d0e94445f527e9a0f95ee9a5ff8095 Mon Sep 17 00:00:00 2001 From: Robert Bright Date: Mon, 9 Apr 2018 21:26:16 +0100 Subject: [PATCH 2/5] Create README.md --- README.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 000000000..f2c76fe97 --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +# learn_ruby +#Projet de Test Driven Development + +Le Projet à été modifié par YVAN WETOMDE et ROBERT BRIGHT + From c03a0441f076273f2a4712b68c2ad05f043f6b57 Mon Sep 17 00:00:00 2001 From: Robert Bright Date: Mon, 9 Apr 2018 22:05:39 +0100 Subject: [PATCH 3/5] Nouvelle version du fichier --- 00_hello/hello.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/00_hello/hello.rb b/00_hello/hello.rb index 251797306..af1288829 100644 --- a/00_hello/hello.rb +++ b/00_hello/hello.rb @@ -1 +1,8 @@ #write your code here +def hello + "Hello!" +end + +def greet(nom) + "Hello, #{nom}!" +end \ No newline at end of file From 6f73dc6a14089f0447b46cf4ede56cbf745b1151 Mon Sep 17 00:00:00 2001 From: Robert Bright Date: Tue, 10 Apr 2018 00:20:01 +0100 Subject: [PATCH 4/5] Modification du fichier temperature.rb --- 01_temperature/temperature.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/01_temperature/temperature.rb b/01_temperature/temperature.rb index 251797306..3522ca327 100644 --- a/01_temperature/temperature.rb +++ b/01_temperature/temperature.rb @@ -1 +1,8 @@ #write your code here +def ftoc (t_degre_f = 3.1 ) + ((t_degre_f - 32) / 1.8).round(1) +end + +def ctof (t_degre_c) + (t_degre_c * (1.8)) + 32 +end \ No newline at end of file From 13a20b3b8eabeed8a929e023087d6438b4012aa2 Mon Sep 17 00:00:00 2001 From: Robert Bright Date: Tue, 10 Apr 2018 01:40:23 +0100 Subject: [PATCH 5/5] Ajout de la calculatrice maj --- 02_calculator/calculator.rb | 40 ++++++++++++++++++++++++++++++++ 02_calculator/calculator_spec.rb | 32 ++++++++++++++++++------- 2 files changed, 64 insertions(+), 8 deletions(-) diff --git a/02_calculator/calculator.rb b/02_calculator/calculator.rb index 251797306..5c19dd76a 100644 --- a/02_calculator/calculator.rb +++ b/02_calculator/calculator.rb @@ -1 +1,41 @@ #write your code here +def add(nombre_a, nombre_b) + nombre_a + nombre_b +end + +def subtract(nombre_a, nombre_b) + if nombre_a < nombre_b + nombre_b - nombre_a + else + nombre_a - nombre_b + end +end + +def sum(tableau) + if tableau == [] + 0 + else + tableau.map { |e| e.to_i} + tableau.inject(0) { |mem, var| mem + var} + end +end + +def multiply(tableau) + if tableau == [] + 0 + else + tableau.inject(1) { |mem, var| mem * var} + end +end + +def power(nombre_a, nombre_b) + (nombre_a.to_i) ** (nombre_b.to_i) +end + +def factorial(nombre) + if nombre == 0 + 1 + else + nombre * factorial(nombre -1) + end +end \ No newline at end of file diff --git a/02_calculator/calculator_spec.rb b/02_calculator/calculator_spec.rb index fef7e9d00..b59b49b31 100644 --- a/02_calculator/calculator_spec.rb +++ b/02_calculator/calculator_spec.rb @@ -79,21 +79,37 @@ describe "#multiply" do - it "multiplies two numbers" + it "multiplies two numbers" do + expect(multiply([2,5])).to eq(10) + end - it "multiplies several numbers" + it "multiplies several numbers" do + expect(multiply((1..10).to_a)).to eq(3628800) + end end describe "#power" do - it "raises one number to the power of another number" + it "raises one number to the power of another number" do + expect(power(23,0)).to eq(1) + end end # http://en.wikipedia.org/wiki/Factorial describe "#factorial" do - it "computes the factorial of 0" - it "computes the factorial of 1" - it "computes the factorial of 2" - it "computes the factorial of 5" - it "computes the factorial of 10" + it "computes the factorial of 0" do + expect(factorial(0)).to eq(1) + end + it "computes the factorial of 1" do + expect(factorial(1)).to eq(1) + end + it "computes the factorial of 2" do + expect(factorial(2)).to eq(2) + end + it "computes the factorial of 5" do + expect(factorial(5)).to eq(120) + end + it "computes the factorial of 10" do + expect(factorial(10)).to eq(3628800) + end end