diff --git a/lib/14_find_number.rb b/lib/14_find_number.rb index c23e68b..1af7464 100644 --- a/lib/14_find_number.rb +++ b/lib/14_find_number.rb @@ -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 diff --git a/spec/14_find_number_spec.rb b/spec/14_find_number_spec.rb index 8993f8e..5cd83e1 100644 --- a/spec/14_find_number_spec.rb +++ b/spec/14_find_number_spec.rb @@ -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