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 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 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 diff --git a/README.md b/README.md index 7e7616724..f2c76fe97 100644 --- a/README.md +++ b/README.md @@ -1,53 +1,5 @@ -Test First Ruby -- RSpec 3 Edition -========== +# learn_ruby +#Projet de Test Driven Development -### Set up instructions +Le Projet à été modifié par YVAN WETOMDE et ROBERT BRIGHT -1. Fork this repo -2. Clone your version of the repo to your local machine -3. On your local machine, `cd` into the root folder of this repo in your terminal -4. run `bundle install` to install all the gems this project needs. - -### Getting started with the exercises - -To work through the first exercise, follow this process - -1. `cd` into `00_hello` from the root folder of this project -2. Run `rake`, to run the tests. It will fail with the following error: - ``` - Failures: - - 1) the hello function says hello - Failure/Error: expect(hello).to eq("Hello!") - - NameError: - undefined local variable or method `hello' for # - # ./00_hello/hello_spec.rb:106:in `block (2 levels) in ' - ``` -3. If the test fails to run and you get a `rake aborted! No Rakefile found` or any other error message not like the one above ensure that your working directory (`pwd` to see the path) contains no spaces as this is a common mistake made by people new to Rspec. -3. Read the failure output carefully and write the code that will make it pass -4. Run the tests again with `rake` -5. This will output that one test has passed and another test failure, write the code to make the next test pass. -4. Continue this process until all tests pass (when they are green) you have now completed the exercise. -5. Do this for all the exercises in this project -5. To get hints and tips about each exercise, view the `index.html` file that is included in each exercise folder - - -Basically, this is "error-driven development"... you'll keep running tests, hitting error messages, fixing those messages, running more tests... It is meant to not only test your Ruby skills but also get you comfortable seeing big scary looking stack traces and error messages. Most of the development you do at first will be just like this. In fact, most of *all* development is error-driven. So get comfortable with it! - -### Troubleshooting - -* Don't name any of your directories with spaces in them! It will give you horribly frustrating error messages and code hates dealing with spaces. For instance: - - ```language-bash - # BAD: - /Documents/My Homework/ruby - - # GOOD: - /Documents/my_homework/ruby - ``` - - -### Credit - -This is forked from [https://github.com/alexch/learn_ruby](https://github.com/alexch/learn_ruby), its original creator. diff --git a/instructions.md b/instructions.md new file mode 100644 index 000000000..7e7616724 --- /dev/null +++ b/instructions.md @@ -0,0 +1,53 @@ +Test First Ruby -- RSpec 3 Edition +========== + +### Set up instructions + +1. Fork this repo +2. Clone your version of the repo to your local machine +3. On your local machine, `cd` into the root folder of this repo in your terminal +4. run `bundle install` to install all the gems this project needs. + +### Getting started with the exercises + +To work through the first exercise, follow this process + +1. `cd` into `00_hello` from the root folder of this project +2. Run `rake`, to run the tests. It will fail with the following error: + ``` + Failures: + + 1) the hello function says hello + Failure/Error: expect(hello).to eq("Hello!") + + NameError: + undefined local variable or method `hello' for # + # ./00_hello/hello_spec.rb:106:in `block (2 levels) in ' + ``` +3. If the test fails to run and you get a `rake aborted! No Rakefile found` or any other error message not like the one above ensure that your working directory (`pwd` to see the path) contains no spaces as this is a common mistake made by people new to Rspec. +3. Read the failure output carefully and write the code that will make it pass +4. Run the tests again with `rake` +5. This will output that one test has passed and another test failure, write the code to make the next test pass. +4. Continue this process until all tests pass (when they are green) you have now completed the exercise. +5. Do this for all the exercises in this project +5. To get hints and tips about each exercise, view the `index.html` file that is included in each exercise folder + + +Basically, this is "error-driven development"... you'll keep running tests, hitting error messages, fixing those messages, running more tests... It is meant to not only test your Ruby skills but also get you comfortable seeing big scary looking stack traces and error messages. Most of the development you do at first will be just like this. In fact, most of *all* development is error-driven. So get comfortable with it! + +### Troubleshooting + +* Don't name any of your directories with spaces in them! It will give you horribly frustrating error messages and code hates dealing with spaces. For instance: + + ```language-bash + # BAD: + /Documents/My Homework/ruby + + # GOOD: + /Documents/my_homework/ruby + ``` + + +### Credit + +This is forked from [https://github.com/alexch/learn_ruby](https://github.com/alexch/learn_ruby), its original creator.