diff --git a/lib/14_find_number.rb b/lib/14_find_number.rb index 5da0075..eafd7f0 100644 --- a/lib/14_find_number.rb +++ b/lib/14_find_number.rb @@ -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 diff --git a/spec/14_find_number_spec.rb b/spec/14_find_number_spec.rb index 1543672..488d076 100644 --- a/spec/14_find_number_spec.rb +++ b/spec/14_find_number_spec.rb @@ -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 @@ -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