Skip to content

Commit

Permalink
Refactor tests for more clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg committed Aug 10, 2009
1 parent e1eb6db commit 5145d41
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 20 deletions.
6 changes: 2 additions & 4 deletions test/integration/go_fish_test.rb
Expand Up @@ -19,14 +19,12 @@ def test_fish_today_pop_eq_100
end

def test_fish_today_pop_eq_25
pop = 25
install_weather_service_uri_mocks(pop)
install_weather_service_uri_mocks(25)
assert_equal GoFish.positive_response, GoFish.fish_today?
end

def test_fish_today_pop_eq_26
pop = 26
install_weather_service_uri_mocks(pop)
install_weather_service_uri_mocks(26)
assert_equal GoFish.negative_response, GoFish.fish_today?
end

Expand Down
20 changes: 10 additions & 10 deletions test/unit/fishing_forecaster_test.rb
Expand Up @@ -21,16 +21,6 @@ def test_weather_forecaster_getter_setter
assert_equal weather_forecaster, FishingForecaster.weather_forecaster
end

def test_likelihood_of_catch_inversely_related_to_likelihood_of_rain
last_likelihood_of_catch = nil
[0, 0.1, 0.2, 0.3, 0.5, 0.6, 0.7, 0.8, 0.9, 1].each do |rain|
FishingForecaster.weather_forecaster = stub(:likelihood_of_rain => rain)
likelihood_of_catch = FishingForecaster.likelihood_of_catch
assert last_likelihood_of_catch > likelihood_of_catch if last_likelihood_of_catch
last_likelihood_of_catch = likelihood_of_catch
end
end

def test_likelihood_of_catch_0_likelihood_of_rain
FishingForecaster.weather_forecaster = stub(:likelihood_of_rain => 0)
assert_equal 1.0, FishingForecaster.likelihood_of_catch
Expand All @@ -41,6 +31,16 @@ def test_likelihood_of_catch_1_likelihood_of_rain
assert_equal 0.0, FishingForecaster.likelihood_of_catch
end

def test_likelihood_of_catch_inversely_related_to_likelihood_of_rain
last_likelihood_of_catch = nil
[0, 0.1, 0.2, 0.3, 0.5, 0.6, 0.7, 0.8, 0.9, 1].each do |rain|
FishingForecaster.weather_forecaster = stub(:likelihood_of_rain => rain)
likelihood_of_catch = FishingForecaster.likelihood_of_catch
assert last_likelihood_of_catch > likelihood_of_catch if last_likelihood_of_catch
last_likelihood_of_catch = likelihood_of_catch
end
end

def test_likelihood_of_catch_calculated_with_sqrt_rain
rain = 0.5
sqrt_rain = 0.707106781186548
Expand Down
9 changes: 3 additions & 6 deletions test/unit/go_fish_test.rb
Expand Up @@ -23,20 +23,17 @@ def test_positive_and_negative_response_differ
end

def test_fish_today_lt_50_percent_likelihood_of_catch
likelihood_of_catch = 0.49
GoFish.fishing_forecaster = stub(:likelihood_of_catch => likelihood_of_catch)
GoFish.fishing_forecaster = stub(:likelihood_of_catch => 0.49)
assert_equal GoFish.negative_response, GoFish.fish_today?
end

def test_fish_today_eq_50_percent_likelihood_of_catch
likelihood_of_catch = 0.50
GoFish.fishing_forecaster = stub(:likelihood_of_catch => likelihood_of_catch)
GoFish.fishing_forecaster = stub(:likelihood_of_catch => 0.50)
assert_equal GoFish.positive_response, GoFish.fish_today?
end

def test_fish_today_gt_50_percent_likelihood_of_catch
likelihood_of_catch = 0.51
GoFish.fishing_forecaster = stub(:likelihood_of_catch => likelihood_of_catch)
GoFish.fishing_forecaster = stub(:likelihood_of_catch => 0.51)
assert_equal GoFish.positive_response, GoFish.fish_today?
end

Expand Down

0 comments on commit 5145d41

Please sign in to comment.