Skip to content
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

panda, tiger, eagle levels #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

noahpatterson
Copy link

No description provided.

end

def winner
return tie if @fighter_a_move.type == :block and @fighter_b_move.type == :block
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably want to use && in most cases of and. Same with || and or (reasons: http://devblog.avdi.org/2010/08/02/using-and-and-or-in-ruby/)

@jwo
Copy link
Member

jwo commented Feb 3, 2014

Truly excellent work. Most people get stuck on the Building the match vs replaying the match. yay!

@noahpatterson
Copy link
Author

I got stuck on getting the turn_specs to work. I've read other places that using 'instance_variable_set' is probably testing internal state and not the result. Is this true? What would the alternative approach be? I feel like the ruby stuff is going well but I spend most of my time trying to write tests. I definitely need more test writing practice.

Thanks again for reviewing!

@jwo
Copy link
Member

jwo commented Feb 3, 2014

I've read other places that using 'instance_variable_set' is probably testing internal state and not the result. Is this true?

Yes, that's true.

If you feel the need to do that, you should extract logic to "Collaborators". That is, have the class that has internal variables you want to touch, and move the logic to something where you can send in the conditions you need in order to make changes.

In this case, the trickiest part is deciding upon Random -- making decisions based upon a random result. So, you can extract Random out into a class you own, and fix the results based on what outcome you want to test.

If you give an example, I can help in more concrete terms :)

[fighter_a, fighter_b].should include subject.winner
end

it "should determine winner by rank on strike vs strike" do
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hopefully this is what you meant be specific example:

In turn.rb I create a turn with 2 Fighters. These fighters already have moves assigned on creation.

  1. I need to assign a specific move and ranking for testing
    Next, Turn randomly chooses a move for each fighter.
  2. I need to assign a specific move to each fighter so I can test that the right move won

Are you saying I should have created a method #random on Turn that took 2 Moves so that when testing I could send in the Moves I want?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, so maybe instead of

[move_a, move_b].sample

You could have a method

choose_random [move_a, move_b]

And then you have full control over choose_random

muhahahaha 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants