Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #251 from railsgirls/guide-updates

Guide updates
  • Loading branch information...
commit fe593a1fa1340ea47aa40ccf4c67b59f6ed87d13 2 parents 09d4d92 + 022e3c2
@lbain lbain authored
View
22 _posts/2014-05-09-test-driven-development.markdown
@@ -52,6 +52,8 @@ also.
- Pick somebody to start in the hot seat. That person should follow all the
steps until swapping seats is mentioned.
+**Coach:** Explain how pair programming can be useful.
+
## *1.* Initial code
Copy this code into a file called `roman.rb`:
@@ -73,8 +75,8 @@ end
**Run your tests**
-If you use *Sublime Text* on Linux, OSX Mavericks (or better) or Windows, you
-can run the tests by pressing `Ctrl-B`. Otherwise you can type the follow into
+If you use *Sublime Text* on Linux, OSX Mavericks (or later) or Windows, you
+can run the tests by pressing `Ctrl-B`. Otherwise you can type the following into
your terminal:
{% highlight sh %}
@@ -101,6 +103,8 @@ assertions, 1 failures, 0 errors, 0 skips`.
**Stand up** and give the hot seat to the next person.
+**Coach:** Explain how TDD can be useful.
+
## *2.* Make the tests pass
It is time to make the test pass. Do this however you see fit. It's fine if the
@@ -126,19 +130,20 @@ Look over the code and decide if it's a good idea to **refactor** it (clean up
the code and make it easier to read). If you decide to not to refactor, skip
this step.
-**Hint**: It's a good time to refactor are when you notice *repetition*. If you
+**Hint**: It's a good time to refactor when you notice *repetition*. If you
like, you can also refactor the tests.
Run your tests after refactoring. If they fail, you accidentally broke
something.
+**Coach:** Explain how focusing on something small enough to test can be useful.
+
## *4.* Write a new failing test
If you all agree that the code should work in general, and you can't think of
any more cases to test and everything passes, you can stop here. You win!
-Otherwise, your last job in the hot seat is to write a new test: one that fails.
-If you're stuck, there are some suggestions at the bottom of this page.
+Otherwise, your last job in the hot seat is to write a new test. We currently have a test that checks that the number one is turned into an `"I"`, but we need more tests to verify that all other numbers convert as expected. When you add a new test for another number, be sure to run the tests to find your test fail. If you're stuck, there are some suggestions at the bottom of this page.
You can copy and paste the previous test and alter it. You can change it to be
anything you like. Your tests should probably test the next trickiest
@@ -146,8 +151,7 @@ situation, but if you feel like going back and adding a simpler case, that's
fine too as long as it fails.
The other members of the group can chime in and ask questions or spot problems
-for you. It's their job to help you. If they're not being helpful, politely let
-them know.
+for you.
Here is an example of an expanded test suite:
@@ -157,8 +161,8 @@ describe "roman" do
roman(1).must_equal "I"
end
- it "converts the number 4 to the string IIII" do
- roman(4).must_equal "IIII"
+ it "converts the number 2 to the string II" do
+ roman(2).must_equal "II"
end
end
{% endhighlight %}
View
52 _posts/2014-05-10-ruby-atm.markdown
@@ -4,9 +4,11 @@ title: Ruby ATM
permalink: ruby-atm
---
+# Ruby ATM
+
*Created by Joshua Paling, [@joshuapaling](https://twitter.com/joshuapaling)*
-In this exercise you will write a function to handle withdrawing money from an ATM. It is intended to challenge you - it is harder than the previous excercises, so you should do them first! Be prepared to ask lots of questions, Google things, and take a step back from the computer. But you'll learn a lot!
+In this exercise you will write a function to handle withdrawing money from an ATM. It is intended to challenge you! Be prepared to ask lots of questions, Google things, and take a step back from the computer. But you'll learn a lot!
You should use pair, group, or remote programming so you have other programmers to bounce ideas off. You'll use Test Driven Development. However, all the tests have been pre-written for you, so you can focus on the code itself.
@@ -24,7 +26,21 @@ For each step, you will need to take the following actions:
You may recognise these steps as the **red, green, refactor** workflow of TDD.
-## *0.*Set up your file
+## *1.* $5 bills
+
+Imagine an ATM that holds only $5 notes. Write a function that returns `true` if an amount can be returned, and `false` otherwise.
+
+**Examples:**
+
+* `withdraw(15)` should return `true`
+* `withdraw(18)` should return `false`, because $18 cannot be made up of $5 notes
+
+**Tips for getting tests green:**
+
+The modulus operator, `%` gets the remainder of a division. Eg, `9 % 4` results in `1` (nine divided by four has a remainder of 1).
+
+**Starting code:**
+
Create a file called `atm.rb`. paste the following code into it. This contains the shell of your `withdraw()` function, along with tests.
{% highlight ruby %}
@@ -34,7 +50,12 @@ def withdraw(amount)
end
# ToDo: figure out this bit
end
+{% endhighlight %}
+
+### Tests for step 1:
+
+{% highlight ruby %}
# import required testing libraries
require 'minitest/spec'
require 'minitest/autorun'
@@ -60,19 +81,6 @@ describe 'atm' do
end
{% endhighlight %}
-## *1.* $5 bills
-
-Imagine an ATM that holds only $5 notes. Write a function that returns `true` if an amount can be returned, and `false` otherwise.
-
-**Examples:**
-
-* `withdraw(15)` should return `true`
-* `withdraw(18)` should return `false`, because $18 cannot be made up of $5 notes
-
-**Tips for getting tests green:**
-
-The modulus operator, `%` gets the remainder of a division. Eg, `9 % 4` results in `1` (nine divided by four has a remainder of 1).
-
## *2.* How many bills?
Now, modify your function so that if the amount *can* be withdrawn, it will return the appropriate number of notes, rather than simply `true`
@@ -125,7 +133,7 @@ end
In programming, an `array` is basically a collection of things. It's like a list.
-Rather than returning the number of notes, Code so that it returns an array of notes (in this case, all $5's).
+Rather than returning the number of notes, modify the code so that it returns an array of notes (in this case, all $5's).
**Examples**
@@ -136,9 +144,9 @@ Rather than returning the number of notes, Code so that it returns an array of n
`[]` defines an empty array. `[1, 2]` defines an array with two elements (1 and 2).
-The shovel operator (`<<`) adds an element to an array. Eg. `[10, 20] << 30` will add 30 to the array, resulting in `[10, 20, 30]`
+The shovel operator (`<<`) adds an element to an array. Eg. `[10, 20] << 30` will add 30 to the array, resulting in `[10, 20, 30]`.
-the `times` method executes a block of code several times - eg. `5.times { puts 'hello' }` will print 'hello' 5 times.
+The `times` method executes a block of code several times - eg. `5.times { puts 'hello' }` will print 'hello' 5 times.
Bringing it all together:
@@ -276,7 +284,7 @@ To tell if an array is not empty: `!my_array.empty?`
To remove the first element off an array: `my_array.shift`. Eg, `[1, 2, 3].shift` results in `[2, 3]`
-If your function calls a sub-function, keep in mind that Ruby has no concept of 'pass by value'. Variables are always a reference to an object.
+Variables are always a reference to an object.
### Refactor
@@ -311,13 +319,13 @@ end
## *7.* Final Discussion Points
* Given a particular solution *works*, what makes it 'good' or 'bad' code?
-* Can you think of any take-home best practices or principals? Is code structure important? Why?
+* Can you think of any take-home best practices or principles? Is code structure important? Why?
* Did you have any 'Aha!' moments? What were they?
-* Lets say you started a little ATM company, which quickly expanded to become a global success. How suitable is your code for dealing with all denominations of currency, in all nations of the world? Did it get more suitable with each step?
+* Let's say you started a little ATM company, which quickly expanded to become a global success. How suitable is your code for dealing with all denominations of currency, in all nations of the world? Did it get more suitable with each step?
## Challenge! $50 and $20 notes
-Up til now, we've intentionally avoided the case where a smaller note cannot fit evenly into each larger one. For example, we've avoided the case of having only $50s and $20s (where 20 does not divide evenly into 50). Can you see why this case will be harder? If your current code were to include only $50s and $20s, what would happen when you try to withdraw $60, or $110? In your head, or on paper, can you think of what logic would need to be in place to handle these cases correctly? If you're up for a challenge, try to handle this case in your code! (You'll need to write the tests yourself for this step).
+Up til now, we've intentionally avoided the case where a smaller note cannot fit evenly into each larger one. For example, we've avoided the case of having only $50s and $20s (where 20 does not divide evenly into 50). Can you see why this case will be harder? If your current code were to include only $50s and $20s, what would happen when you try to withdraw $60, or $110? In your head, or on paper, can you think of what logic would be needed to be in place to handle these cases correctly? If you're up for a challenge, try to handle this case in your code! (You'll need to write the tests yourself for this step).
Please sign in to comment.
Something went wrong with that request. Please try again.