Skip to content

Commit

Permalink
Complete asignment TheOdinProject#3
Browse files Browse the repository at this point in the history
  • Loading branch information
missopi committed Aug 19, 2023
1 parent 303f495 commit b32266a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
6 changes: 5 additions & 1 deletion lib/14_find_number.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ def make_guess
end

def game_over?
@guess == @answer
guess == answer
end

def update_range
guess < answer ? @min = guess + 1 : @max = guess - 1
end
end
38 changes: 32 additions & 6 deletions spec/14_find_number_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -220,20 +220,36 @@
context 'when the guess is less than the answer' do
subject(:low_guess_game) { described_class.new(0, 9, number_range, 4) }

xit 'updates min to 5' do
before do
low_guess_game.update_range
end

xit 'does not update max' do
it 'updates min to 5' do
min_after_guess = low_guess_game.min
expect(min_after_guess).to eq(5)
end

it 'does not update max' do
max_after_guess = low_guess_game.max
expect(max_after_guess).to eq(9)
end
end

context 'when the guess is more than the answer' do
subject(:high_guess_game) { described_class.new(0, 9, number_range, 9) }

xit 'does not update min' do
before do
high_guess_game.update_range
end

it 'does not update min' do
min_after_guess = high_guess_game.min
expect(min_after_guess).to eq(0)
end

xit 'updates max to 8' do
it 'updates max to 8' do
max_after_guess = high_guess_game.max
expect(max_after_guess).to eq(8)
end
end

Expand All @@ -249,10 +265,20 @@
# Write a test for any 'edge cases' that you can think of, for example:

context 'when the guess is 7, min=5, and max=8' do
xit 'updates min to the same value as max' do
subject(:high_guess_game) { described_class.new(5, 8, number_range, 7) }

before do
high_guess_game.update_range
end

it 'updates min to the same value as max' do
min_after_guess = high_guess_game.max
expect(min_after_guess).to eq(8)
end

xit 'does not update max' do
it 'does not update max' do
max_after_guess = high_guess_game.max
expect(max_after_guess).to eq(8)
end
end
end
Expand Down

0 comments on commit b32266a

Please sign in to comment.