-
Notifications
You must be signed in to change notification settings - Fork 26
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
&&: Aruna & Kate #10
base: master
Are you sure you want to change the base?
&&: Aruna & Kate #10
Conversation
Aruna branch
creates test and code for '#draw_tiles'
refactors tilebag init to turn it into a collection of tiles
redesigns #draw_tiles and #tiles_remaining tests and code
ScrabbleWhat We're Looking For
|
end | ||
|
||
it 'returns the highest word if there are two words' do | ||
|
||
Scrabble::Scoring.highest_score_from(["dog", "rooster"]).must_equal "rooster" |
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.
In these tests you should also vary up the order, just to make sure the order of the elements isn't determining the answer.
Scrabble::Scoring.highest_score_from(["dog", "rooster"]).must_equal "rooster"
Scrabble::Scoring.highest_score_from(["rooster", "dog"]).must_equal "rooster"
Also what about testing a list of words with an invalid word in the mix.
score = 0 | ||
letters_array.each do |letter| | ||
case letter | ||
when "a" ,"e","i","o", "u", "l", "n", "r" ,"s","t" |
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.
This works, but is there a more compact way to do this using a hash?
# Arrange | ||
# Act | ||
# Assert | ||
Scrabble::Scoring.highest_score_from([]).must_be_nil |
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.
Good, now what about an invalid word in the list?
module Scrabble | ||
class Player | ||
attr_reader :name, :plays, :total | ||
attr_accessor :tiles |
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.
This should not be an accessor.
@name = name | ||
@plays = Array.new | ||
@total = 0 | ||
@tilebag = Scrabble::Tilebag.new |
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.
Each player should NOT receive their own TileBag. Instead use the parameter provided to draw_tiles
.
it "returns true if total_score greater than or equal to 100" do | ||
|
||
@player.play("qqqq") | ||
@player.total_score |
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.
won?
shouldn't fail if the user doesn't call total_score
first.
|
||
describe "# draw_tiles method" do | ||
it "Should be a collection of letters" do | ||
|
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.
You're not testing the draw_tiles
method!
end | ||
|
||
def tiles_remaining | ||
@tiles.length - @drawn_tiles.length |
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.
This isn't working
|
||
def draw_tiles(tilebag) | ||
num = 7 - @tiles.length | ||
replace_tiles = Scrabble::Tilebag.draw_tiles(num) |
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.
You're calling draw_tiles
like a class method, not an instance method of tilebag
Should be:
tilebag.draw_tiles(num)
|
||
describe '#draw_tiles(num)' do | ||
it "returns an array of tiles" do | ||
@tilebag.draw_tiles(9) |
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.
This test is failing
if array_of_words == [] | ||
return nil | ||
elsif array_of_words.length == 1 | ||
winning_word_array << array_of_words |
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.
If you're just going to return 1 word, why push array_of_words
into winning_word_array
instead return array_of_words[0]
Scrabble
Congratulations! You're submitting your assignment.
Comprehension Questions
score
method in theScoring
class a class method instead of an instance method?Enumerable
mixin? If so, where and why was it helpful?max_by
andmin_by
to help with the code that decided a winner when there was a tie. It was helpful because it cut down on code that needed to be changed, and made the code base less bulky.