You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+29-17Lines changed: 29 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,12 +24,7 @@ give you guidance as to which tests failed. (You can check the [RSpec
24
24
documentation](http://rspec.info) to see how the `.rspec` file can be
25
25
used to customize the output format.)
26
26
27
-
* If you want to be really cool, run `autotest`. This will run all the
28
-
tests in `spec/`, but every time you edit and save your code file, the
29
-
tests are automatically re-run, so you don't have to run them manually.
30
-
As we'll see later, this is the first step to TDD or test-driven
31
-
development: write the tests before you write the code, watch the test
32
-
fail, fill in the code and save the code file, then watch the test pass!
27
+
33
28
34
29
35
30
# 1. Arrays, Hashes, and Enumerables
@@ -38,43 +33,60 @@ Check the [Ruby 2.x documentation](http://ruby-doc.org) on `Array`,
38
33
`Hash` and `Enumerable` as they could help tremendously with these
39
34
exercises. :-)
40
35
41
-
0. Define a method `sum(array)` that takes an array of integers as an argument and returns the sum of its elements. For an empty array it should return zero.
36
+
0. Define a method `sum(array)` that takes an array of integers as an argument and returns the sum of its elements. For an empty array it should return zero. Run associated tests via: `$ rspec spec/part1_spec.rb:5`
42
37
43
-
0. Define a method `max_2_sum(array)` which takes an array of integers as an argument and returns the sum of its two largest elements. For an empty array it should return zero. For an array with just one element, it should return that element.
38
+
0. Define a method `max_2_sum(array)` which takes an array of integers as an argument and returns the sum of its two largest elements. For an empty array it should return zero. For an array with just one element, it should return that element. Run associated tests via: `$ rspec spec/part1_spec.rb:23`
44
39
45
-
0. Define a method `sum_to_n?(array, n)` that takes an array of integers and an additional integer, n, as arguments and returns true if any two elements in the array of integers sum to n. `sum_to_n?([], n)` should return false for any value of n, by definition.
40
+
0. Define a method `sum_to_n?(array, n)` that takes an array of integers and an additional integer, n, as arguments and returns true if any two elements in the array of integers sum to n. `sum_to_n?([], n)` should return false for any value of n, by definition. Run associated tests via: `$ rspec spec/part1_spec.rb:42`
46
41
47
-
You can check your progress by running `rspec spec/part1_spec.rb`, or
48
-
just running `autotest` and leaving it running.
42
+
You can check your progress on the all the above by running `$ rspec spec/part1_spec.rb`.
49
43
50
44
# 2. Strings and Regular Expressions
51
45
52
46
Check the documentation on String and Regexp as they could help tremendously with these exercises. :-)
53
47
54
-
0. Define a method `hello(name)` that takes a string representing a name and returns the string "Hello, " concatenated with the name.
48
+
0. Define a method `hello(name)` that takes a string representing a name and returns the string "Hello, " concatenated with the name. Run associated tests via: `$ rspec -e '#hello' spec/part2_spec.rb`
55
49
56
-
0. Define a method `starts_with_consonant?(s)` that takes a string and returns true if it starts with a consonant and false otherwise. (For our purposes, a consonant is any letter other than A, E, I, O, U.) NOTE: be sure it works for both upper and lower case and for nonletters!
50
+
0. Define a method `starts_with_consonant?(s)` that takes a string and returns true if it starts with a consonant and false otherwise. (For our purposes, a consonant is any letter other than A, E, I, O, U.) NOTE: be sure it works for both upper and lower case and for nonletters! Run associated tests via: `$ rspec -e '#starts_with_consonant?' spec/part2_spec.rb`
57
51
58
-
0. Define a method `binary_multiple_of_4?(s)` that takes a string and returns true if the string represents a binary number that is a multiple of 4. NOTE: be sure it returns false if the string is not a valid binary number!
52
+
0. Define a method `binary_multiple_of_4?(s)` that takes a string and returns true if the string represents a binary number that is a multiple of 4. NOTE: be sure it returns false if the string is not a valid binary number! Run associated tests via: `$ rspec -e '#binary_multiple_of_4?' spec/part2_spec.rb`
59
53
54
+
You can check your progress on the all the above by running `$ rspec spec/part2_spec.rb`.
60
55
61
56
# 3. Object Oriented Basics
62
57
63
58
64
59
Define a class `BookInStock` which represents a book with an ISBN
65
60
number, `isbn`, and price of the book as a floating-point number,
66
-
`price`, as attributes.
61
+
`price`, as attributes. Run associated tests via: `$ rspec -e 'getters and setters' spec/part3_spec.rb`
67
62
68
63
The constructor should accept the ISBN number
69
64
(a string, since in real life ISBN numbers can begin with zero and can
70
65
include hyphens) as the first argument and price as second argument, and
71
66
should raise `ArgumentError` (one of Ruby's built-in exception types) if
72
67
the ISBN number is the empty string or if the price is less than or
73
68
equal to zero. Include the proper getters and setters for these
74
-
attributes.
69
+
attributes. Run associated tests via: `$ rspec -e 'constructor' spec/part3_spec.rb`
75
70
76
71
Include a method `price_as_string` that returns the price of
77
72
the book formatted with a leading dollar sign and two decimal places, that is, a price
78
73
of 20 should format as "$20.00" and a price of 33.8 should format as
79
-
"$33.80".
74
+
"$33.80". Run associated tests via: `$ rspec -e '#price_as_string' spec/part3_spec.rb`
75
+
76
+
You can check your progress on the all the above by running `rspec spec/part3_spec.rb`.
77
+
78
+
## More Challenges
79
+
80
+
* Try getting setup with
81
+
an automated test framework such as [guard](http://code.tutsplus.com/tutorials/testing-your-ruby-code-with-guard-rspec-pry--cms-19974) or [autotest](https://rubygems.org/gems/autotest). Guard or AutoTest can be set up so that
82
+
they will run all the tests in `spec/`, but every time you edit and save
83
+
your code file, the tests are automatically re-run, so you don't have to
84
+
run them manually. As we'll see later, this is the "watch the test fail"
85
+
part of the TDD or test-driven process of development: write the tests before
86
+
you write the code, watch the test fail, fill in the code and save the code file,
87
+
then watch the test pass!
88
+
89
+
* Try pairing using the [one-undermanship pair programming style](http://www.agileventures.org/remote-pair-programming/pair-programming-protocols)
0 commit comments