Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions minitest/navy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,49 @@ def fire_upon_target
@battleship.fire!
end

def has_battleship
battleship = Battleship.new
end
end

class Battleship
attr_reader :ammunition
attr_reader :ammunition, :request
def initialize
@ammunition = 100
@ammunition = 10
@request = request
end

def fire!
@ammunition = @ammunition - 1
end

def request
Copy link
Member

Choose a reason for hiding this comment

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

you have a method request and an attr_reader request. why? and do you understand why you can't do that?

Copy link
Author

Choose a reason for hiding this comment

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

Oh that is a mistake. I made the "request" method to assign the value true. Although, I do not really know why doing both is not a good idea

Copy link
Member

Choose a reason for hiding this comment

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

Here's a reason why that's no good. The def temp overrides the attr_accessor http://rubyfiddle.com/riddles/f1f85

true
end

def more_ammunition
true
end

def verify
if "hit"
Copy link
Member

Choose a reason for hiding this comment

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

This will always be a hit, right? What are you trying to do?

Copy link
Author

Choose a reason for hiding this comment

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

My goals is to pass in something equal to either a "hit" or "miss" my problem is that i do not know what that something is yet

Copy link
Member

Choose a reason for hiding this comment

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

In order to really tell if you hit something, you'd need a board with positions of ships. And, you'd have to give the "fire" a target. Very out of scope for this lesson.

Instead, if you just need a reason, just random number

if rand > 0.5
  :hit
else
  :miss
end

"hit"
else
"miss"
end
end
end

class Fate
attr_reader :ammunition

def initalize
@hit = hit
@miss = miss
end

def outcome
[:hit, :miss].sample
end
end

30 changes: 28 additions & 2 deletions minitest/navy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,43 @@ def setup
def test_can_tell_the_battleship_to_fire
@battleship.expect :fire!, nil
@admiral.fire_upon_target
@battleship.verify
@battleship.verify.must_equal (true)
end

def test_has_battleship
battleship = Battleship.new
end
end

class TestBattleship< MiniTest::Unit::TestCase
class TestBattleship < MiniTest::Unit::TestCase
def test_will_decrease_ammunition_when_firing
battleship = Battleship.new
starting_ammunition = battleship.ammunition
battleship.fire!
assert_equal (starting_ammunition - 1), battleship.ammunition
end

def test_ammunition
battleship = Battleship.new
starting_ammunition = battleship.ammunition
end

def test_request_more_ammunition
battleship = Battleship.new
battleship.request.must_equal (true)
end

def test_battleship_can_receive_more_ammunition
battleship = Battleship.new
starting_ammunition = battleship.ammunition
battleship.more_ammunition.must_equal (true)
end
end

class TestFate < MiniTest::Unit::TestCase
def test_outcome
#Not sure here
end
end

describe Battleship do
Expand Down