Skip to content

Commit

Permalink
Partial assignment method TheOdinProject#3
Browse files Browse the repository at this point in the history
  • Loading branch information
lohikaarme committed Dec 6, 2023
1 parent 71a85d3 commit 81998b3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
11 changes: 11 additions & 0 deletions lib/14_find_number.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,15 @@ def make_guess(min = @min, max = @max)
def game_over?
return true if @guess == @answer
end

def update_range
case @guess <=> @answer
when -1
@min = @guess + 1
when 0
return
when 1
@max = @guess - 1
end
end
end
24 changes: 20 additions & 4 deletions spec/14_find_number_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -219,20 +219,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
minimum = low_guess_game.min
expect(minimum).to eq(5)
end

it 'does not update max' do
maximum = low_guess_game.max
expect(maximum).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
minimum = high_guess_game.min
expect(minimum).to eq(0)
end

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

Expand Down

0 comments on commit 81998b3

Please sign in to comment.