forked from turingschool-examples/ruby-exercises
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
438 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Objects and Methods | ||
|
||
## Exercise 1 | ||
|
||
If you'd like to be walked through the exercise, check out the [Objects and Methods](http://tutorials.jumpstartlab.com/academy/workshops/objects_and_methods.html) workshop on the Jumpstart Lab tutorials site. | ||
|
||
Make the tests pass in the following sequence: | ||
|
||
* `test/candy_test.rb` | ||
* `test/bag_test.rb` | ||
* `test/costume_test.rb` | ||
* `test/trick_or_treater_test.rb` | ||
|
||
Run a test file by calling it with `ruby`: | ||
|
||
```bash | ||
$ ruby test/bag_test.rb | ||
``` | ||
|
||
## Exercise 2 | ||
|
||
Each object has become a little bit more complex. | ||
|
||
Make the tests pass in the following sequence: | ||
|
||
* `test/candy_test.rb` | ||
* `test/bag_test.rb` | ||
* `test/costume_test.rb` | ||
* `test/trick_or_treater_test.rb` | ||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
gem 'minitest', '~> 5.2' | ||
require 'minitest/autorun' | ||
require 'minitest/pride' | ||
require_relative '../lib/bag' | ||
require_relative '../lib/candy' | ||
|
||
class BagTest < Minitest::Test | ||
def test_a_new_bag_is_empty | ||
assert Bag.new.empty? | ||
end | ||
|
||
def test_count_the_candies_in_an_empty_bag | ||
skip | ||
assert_equal 0, Bag.new.count | ||
end | ||
|
||
def test_empty_bag_has_no_candies | ||
skip | ||
assert_equal [], Bag.new.candies | ||
end | ||
|
||
def test_put_candy_in_the_bag | ||
skip | ||
bag = Bag.new | ||
candy = Candy.new("Sour frogs") | ||
bag << candy | ||
assert_equal [candy], bag.candies | ||
end | ||
|
||
def test_a_bag_with_candies_is_not_empty | ||
skip | ||
bag = Bag.new | ||
bag << Candy.new("Nerds") | ||
refute bag.empty? | ||
end | ||
|
||
def test_bag_counts_candies | ||
skip | ||
bag = Bag.new | ||
bag << Candy.new("Caramelized Almonds") | ||
assert_equal 1, bag.count | ||
end | ||
|
||
def test_bag_contains_candies_and_candies_have_a_type | ||
skip | ||
bag = Bag.new | ||
bag << Candy.new("Hershey's Kisses") | ||
# You usually don't want to chain a bunch of different | ||
# types of things together like this. | ||
# We'll talk about it more in a few weeks. | ||
# It's important to understand how these methods work, though. | ||
type = bag.candies.first.type | ||
assert_equal "Hershey's Kisses", type | ||
end | ||
|
||
def test_ask_bag_if_it_contains_a_particular_type_of_candy | ||
skip | ||
bag = Bag.new | ||
bag << Candy.new("Lindt chocolate") | ||
|
||
assert bag.contains?("Lindt chocolate") | ||
refute bag.contains?("Hershey's chocolate") | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
gem 'minitest', '~> 5.2' | ||
require 'minitest/autorun' | ||
require 'minitest/pride' | ||
require_relative '../lib/candy' | ||
|
||
class CandyTest < Minitest::Test | ||
def test_candy_type | ||
candy = Candy.new("Skittles") | ||
assert_equal candy.type, "Skittles" | ||
end | ||
|
||
def test_other_type_of_candy | ||
skip | ||
candy = Candy.new("Mars") | ||
assert_equal candy.type, "Mars" | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
gem 'minitest', '~> 5.2' | ||
require 'minitest/autorun' | ||
require 'minitest/pride' | ||
require_relative '../lib/costume' | ||
|
||
class CostumeTest < Minitest::Test | ||
def test_costume_style | ||
costume = Costume.new("Batman") | ||
assert_equal costume.style, "Batman" | ||
end | ||
|
||
def test_other_style_of_costume | ||
skip | ||
costume = Costume.new("Princess") | ||
assert_equal costume.style, "Princess" | ||
end | ||
end | ||
|
65 changes: 65 additions & 0 deletions
65
objects-and-methods/exercise-1/test/trick_or_treater_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
gem 'minitest', '~> 5.2' | ||
require 'minitest/autorun' | ||
require 'minitest/pride' | ||
require_relative '../lib/costume' | ||
require_relative '../lib/bag' | ||
require_relative '../lib/candy' | ||
require_relative '../lib/trick_or_treater' | ||
|
||
class TrickOrTreaterTest < Minitest::Test | ||
def test_wears_a_costume | ||
costume = Costume.new("Cowboy") | ||
trick_or_treater = TrickOrTreater.new(costume) | ||
assert_equal "Cowboy", trick_or_treater.dressed_up_as | ||
end | ||
|
||
def test_wears_a_different_costume | ||
skip | ||
costume = Costume.new("Pony") | ||
trick_or_treater = TrickOrTreater.new(costume) | ||
assert_equal "Pony", trick_or_treater.dressed_up_as | ||
end | ||
|
||
def test_has_an_empty_bag_by_default | ||
skip | ||
trick_or_treater = TrickOrTreater.new(Costume.new("Alien")) | ||
assert trick_or_treater.bag.empty? | ||
end | ||
|
||
def test_an_empty_bag_means_no_candy | ||
skip | ||
trick_or_treater = TrickOrTreater.new(Costume.new("Knight")) | ||
refute trick_or_treater.has_candy? | ||
end | ||
|
||
def test_gets_candies | ||
skip | ||
trick_or_treater = TrickOrTreater.new(Costume.new("Spaceship Mechanic")) | ||
trick_or_treater.bag << Candy.new("Gummy bears") | ||
assert trick_or_treater.has_candy? | ||
end | ||
|
||
def test_counts_candies | ||
skip | ||
trick_or_treater = TrickOrTreater.new(Costume.new("Spaceship Mechanic")) | ||
assert_equal 0, trick_or_treater.candy_count | ||
trick_or_treater.bag << Candy.new("Gummy bears") | ||
assert_equal 1, trick_or_treater.candy_count | ||
end | ||
|
||
def test_eats_candies | ||
skip | ||
trick_or_treater = TrickOrTreater.new(Costume.new("Baron")) | ||
trick_or_treater.bag << Candy.new("Gummy worms") | ||
trick_or_treater.bag << Candy.new("Liquorice") | ||
trick_or_treater.bag << Candy.new("Salty Serpents") | ||
assert_equal 3, trick_or_treater.candy_count | ||
trick_or_treater.eat | ||
assert_equal 2, trick_or_treater.candy_count | ||
trick_or_treater.eat | ||
assert_equal 1, trick_or_treater.candy_count | ||
trick_or_treater.eat | ||
assert_equal 0, trick_or_treater.candy_count | ||
end | ||
end | ||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
gem 'minitest', '~> 5.2' | ||
require 'minitest/autorun' | ||
require 'minitest/pride' | ||
require_relative '../lib/bag' | ||
require_relative '../lib/candy' | ||
|
||
class BagTest < Minitest::Test | ||
def test_a_new_bag_is_empty | ||
assert Bag.new.empty? | ||
end | ||
|
||
def test_count_the_candies_in_an_empty_bag | ||
skip | ||
assert_equal 0, Bag.new.count | ||
end | ||
|
||
def test_empty_bag_has_no_candies | ||
skip | ||
assert_equal [], Bag.new.candies | ||
end | ||
|
||
def test_put_candy_in_the_bag | ||
skip | ||
bag = Bag.new | ||
candy = Candy.new("Sour frogs") | ||
bag << candy | ||
assert_equal [candy], bag.candies | ||
end | ||
|
||
def test_a_bag_with_candies_is_not_empty | ||
skip | ||
bag = Bag.new | ||
bag << Candy.new("Nerds") | ||
refute bag.empty? | ||
end | ||
|
||
def test_bag_counts_candies | ||
skip | ||
bag = Bag.new | ||
bag << Candy.new("Caramelized Almonds") | ||
assert_equal 1, bag.count | ||
end | ||
|
||
def test_bag_contains_candies_and_candies_have_a_type | ||
skip | ||
bag = Bag.new | ||
bag << Candy.new("Hershey's Kisses") | ||
# You usually don't want to chain a bunch of different | ||
# types of things together like this. | ||
# We'll talk about it more in a few weeks. | ||
# It's important to understand how these methods work, though. | ||
type = bag.candies.first.type | ||
assert_equal "Hershey's Kisses", type | ||
end | ||
|
||
def test_ask_bag_if_it_contains_a_particular_type_of_candy | ||
skip | ||
bag = Bag.new | ||
bag << Candy.new("Lindt chocolate") | ||
|
||
assert bag.contains?("Lindt chocolate") | ||
refute bag.contains?("Hershey's chocolate") | ||
end | ||
|
||
def test_get_a_particular_type_of_candy | ||
skip | ||
bag = Bag.new | ||
bag << Candy.new("Jawbreaker") | ||
bag << Candy.new("Jawbreaker") | ||
bag << Candy.new("Jolly Ranchers") | ||
|
||
candy = bag.grab "Jawbreaker" | ||
assert_equal "Jawbreaker", candy.type | ||
end | ||
|
||
def test_grabbing_candy_removes_it_from_the_bag | ||
skip | ||
bag = Bag.new | ||
bag << Candy.new("Reese's Pieces") | ||
bag << Candy.new("Junior Mints") | ||
bag << Candy.new("Reese's Pieces") | ||
assert_equal 3, bag.count | ||
|
||
candy = bag.grab "Reese's Pieces" | ||
assert_equal 2, bag.count | ||
end | ||
|
||
def test_take_a_number_of_candies_from_the_bag | ||
skip | ||
bag = Bag.new | ||
bag << Candy.new("Swedish Fish") | ||
bag << Candy.new("Milky Way") | ||
bag << Candy.new("Cotton Candy") | ||
|
||
assert_equal 3, bag.count | ||
|
||
taken = bag.take(2) | ||
assert_equal 2, taken.size | ||
assert_equal 1, bag.count | ||
end | ||
|
||
def test_take_one_candy | ||
skip | ||
bag = Bag.new | ||
bag << Candy.new("Lifesavers") | ||
|
||
candy = bag.take(1) | ||
assert_equal "Lifesavers", candy.type | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
gem 'minitest', '~> 5.2' | ||
require 'minitest/autorun' | ||
require 'minitest/pride' | ||
require_relative '../lib/candy' | ||
|
||
class CandyTest < Minitest::Test | ||
def test_candy_type | ||
candy = Candy.new("Skittles") | ||
assert_equal candy.type, "Skittles" | ||
end | ||
|
||
def test_other_type_of_candy | ||
skip | ||
candy = Candy.new("Mars") | ||
assert_equal candy.type, "Mars" | ||
end | ||
|
||
def test_amount_of_sugar_is_100_by_default | ||
skip | ||
candy = Candy.new("Circus Peanuts") | ||
assert_equal 100, candy.sugar | ||
end | ||
|
||
def test_amount_of_sugar_is_configurable | ||
skip | ||
candy = Candy.new("Pop Rocks", 78) | ||
assert_equal 78, candy.sugar | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
gem 'minitest', '~> 5.2' | ||
require 'minitest/autorun' | ||
require 'minitest/pride' | ||
require_relative '../lib/costume' | ||
|
||
class CostumeTest < Minitest::Test | ||
def test_costume_style | ||
costume = Costume.new("Batman") | ||
assert_equal costume.style, "Batman" | ||
end | ||
|
||
def test_other_style_of_costume | ||
skip | ||
costume = Costume.new("Princess") | ||
assert_equal costume.style, "Princess" | ||
end | ||
end | ||
|
Oops, something went wrong.