-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Completed Scrabble Wave 3 #26
base: dfcp+raa/master
Are you sure you want to change the base?
Changes from all commits
39b3afb
de7e458
ea00f99
8d293ab
1fa7cdd
b23c2a5
8a14237
f9aa315
15a466a
215be95
74c2e31
5fb9235
54d06df
baae4ce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module Scrabble | ||
class TileBag | ||
|
||
attr_reader :tile_quantities | ||
def initialize | ||
starting_tiles = %w{A A A A A A A A A B B C C D D D D | ||
E E E E E E E E E E E E F F G G G H H I I I I I I I I I J K | ||
L L L L M M N N N N N N O O O O O O O O P P Q R R R R R R S S | ||
S S T T T T T T U U U U V V W W X Y Y Z} | ||
@tile_quantities = starting_tiles.shuffle! | ||
end | ||
|
||
def draw_tiles(num) | ||
@tile_quantities.pop(num) | ||
end | ||
|
||
def tiles_remaining | ||
@tile_quantities.length | ||
end | ||
|
||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,11 +6,11 @@ | |
@player2 = Scrabble::Player.new("andre") | ||
@player3 = Scrabble::Player.new("batman") | ||
@player4 = Scrabble::Player.new("spiderman") | ||
@player5 = Scrabble::Player.new("superman") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure I understand why there are five separate In general you only need to write a spec with more than one instance of a class if at least one test requires that multiple instances of the class interact with each other. Otherwise, it's perfectly fine to use the same instance from a |
||
@player2.play("love") # love = 7 | ||
@player2.play("toast") # toast = 5 | ||
@player2.play("hand") # hand = 8 | ||
@player3.total = 101 | ||
|
||
@player3.play("zzzzzzzzzzz") # = 110 | ||
end | ||
|
||
describe ".new" do | ||
|
@@ -39,7 +39,7 @@ | |
it "adds the input word to the plays array" do | ||
expect(@player2.plays).to eq ["love", "toast", "hand"] | ||
end | ||
it "returns false is player has already won" do | ||
it "returns false if player has already won" do | ||
expect(@player3.play("word")).to eq false | ||
end | ||
end | ||
|
@@ -59,7 +59,7 @@ | |
expect(@player2.won?).to eq false | ||
end | ||
it "returns false if player does not have over 100 points" do | ||
@player4.total = 100 | ||
@player4.play("zzzzzzzzzz") #word = 100 points exactly | ||
expect(@player4.won?).to eq false | ||
end | ||
end | ||
|
@@ -72,7 +72,24 @@ | |
|
||
describe "#highest_word_score" do | ||
it "returns the highest scoring word score" do | ||
expect(@player2.highest_word_score).to eq 8 | ||
expect(@player2.highest_word_score).to eq 8 | ||
end | ||
end | ||
|
||
describe "#tiles" do | ||
it "returns the collection of letters that the player can play" do | ||
expect(@player5.tiles).to be_an_instance_of Array | ||
end | ||
it "contains a maximum of 7 tiles" do | ||
expect(@player5.tiles.length).to be <= 7 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you explain the reason for this particular test, and how you've chosen to write it? |
||
end | ||
end | ||
|
||
describe "#draw_tiles(tile_bag)" do | ||
it "fills tiles array until it has 7 letters from the given tile bag" do | ||
@tilebag = Scrabble::TileBag.new | ||
@player5.draw_tiles(@tilebag) | ||
expect(@player5.tiles.length).to eq 7 | ||
end | ||
end | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
require "./lib/tilebag" | ||
|
||
describe Scrabble::TileBag do | ||
before :each do | ||
@tilebag1 = Scrabble::TileBag.new | ||
@tilebag2 = Scrabble::TileBag.new | ||
@tilebag2.draw_tiles(4) | ||
end | ||
|
||
describe "#initialize" do | ||
it "sets up an instance of the TileBag class" do | ||
expect(@tilebag1).to be_an_instance_of Scrabble::TileBag | ||
end | ||
it "sets up an instance with a collection of default tiles" do | ||
expect(@tilebag1.tile_quantities).to_not be_empty | ||
expect(@tilebag1.tile_quantities.length).to eq 98 | ||
end | ||
end | ||
|
||
describe "#draw_tiles" do | ||
it "returns the specifed number of random tiles" do | ||
expect(@tilebag2.draw_tiles(4).length).to eq 4 | ||
end | ||
it "Removes the tiles from the default set" do | ||
expect(@tilebag2.tile_quantities.length).to eq 94 | ||
end | ||
end | ||
|
||
describe "#tiles_remaining" do | ||
it " returns the number of tiles remaining in the bag" do | ||
expect(@tilebag2.tiles_remaining).to eq 94 | ||
end | ||
end | ||
|
||
|
||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the reason for having
@bag
as an instance variable rather thanbag
as a local variable?