Commit 671f2fd0c7890fc8f85476d927020829222a3aa2
1 parent
a5557a55
Exists in
master
and in
1 other branch
initialize error_message
Showing
1 changed file
with
16 additions
and
1 deletions
Show diff stats
lib/tasks/test_api.rake
@@ -27,6 +27,7 @@ namespace :test_api do | @@ -27,6 +27,7 @@ namespace :test_api do | ||
27 | end | 27 | end |
28 | 28 | ||
29 | def verify_losses_equals_losing_votes(choice) | 29 | def verify_losses_equals_losing_votes(choice) |
30 | + error_message = "" | ||
30 | success_message = "Choice losses equals losing votes" | 31 | success_message = "Choice losses equals losing votes" |
31 | # votes before 2010-02-17 have null loser_choice_id | 32 | # votes before 2010-02-17 have null loser_choice_id |
32 | # therefore we want to ignore this test for any question with votes | 33 | # therefore we want to ignore this test for any question with votes |
@@ -40,6 +41,7 @@ namespace :test_api do | @@ -40,6 +41,7 @@ namespace :test_api do | ||
40 | end | 41 | end |
41 | 42 | ||
42 | def verify_wins_equals_vote_wins(choice) | 43 | def verify_wins_equals_vote_wins(choice) |
44 | + error_message = "" | ||
43 | success_message = "Choice wins equals vote wins" | 45 | success_message = "Choice wins equals vote wins" |
44 | choice_votes_count = choice.votes.count | 46 | choice_votes_count = choice.votes.count |
45 | if (choice.wins != choice_votes_count) | 47 | if (choice.wins != choice_votes_count) |
@@ -49,6 +51,7 @@ namespace :test_api do | @@ -49,6 +51,7 @@ namespace :test_api do | ||
49 | end | 51 | end |
50 | 52 | ||
51 | def verify_cached_score_equals_computed_score(choice) | 53 | def verify_cached_score_equals_computed_score(choice) |
54 | + error_message = "" | ||
52 | success_message = "Choice has accurate cached score" | 55 | success_message = "Choice has accurate cached score" |
53 | cached_score = choice.score.to_f | 56 | cached_score = choice.score.to_f |
54 | generated_score = choice.compute_score.to_f | 57 | generated_score = choice.compute_score.to_f |
@@ -63,6 +66,7 @@ namespace :test_api do | @@ -63,6 +66,7 @@ namespace :test_api do | ||
63 | end | 66 | end |
64 | 67 | ||
65 | def verify_valid_cached_score(choice) | 68 | def verify_valid_cached_score(choice) |
69 | + error_message = "" | ||
66 | success_message = "Choice has valid cached score" | 70 | success_message = "Choice has valid cached score" |
67 | cached_score = choice.score.to_f | 71 | cached_score = choice.score.to_f |
68 | if cached_score == 0.0 || cached_score == 100.0 || cached_score.nil? | 72 | if cached_score == 0.0 || cached_score == 100.0 || cached_score.nil? |
@@ -72,6 +76,7 @@ namespace :test_api do | @@ -72,6 +76,7 @@ namespace :test_api do | ||
72 | end | 76 | end |
73 | 77 | ||
74 | def verify_cached_prompt_counts(choice) | 78 | def verify_cached_prompt_counts(choice) |
79 | + error_message = "" | ||
75 | success_message = "Choice has accurate prompt cache count" | 80 | success_message = "Choice has accurate prompt cache count" |
76 | if choice.prompts_on_the_left.count != choice.prompts_on_the_left_count || choice.prompts_on_the_right.count != choice.prompts_on_the_right_count | 81 | if choice.prompts_on_the_left.count != choice.prompts_on_the_left_count || choice.prompts_on_the_right.count != choice.prompts_on_the_right_count |
77 | error_message = "Choice #{choice.id} in Question ##{choice.question_id} has inaccurate prompt count cache" | 82 | error_message = "Choice #{choice.id} in Question ##{choice.question_id} has inaccurate prompt count cache" |
@@ -80,6 +85,7 @@ namespace :test_api do | @@ -80,6 +85,7 @@ namespace :test_api do | ||
80 | end | 85 | end |
81 | 86 | ||
82 | def verify_choice_appearances_and_votes(choice) | 87 | def verify_choice_appearances_and_votes(choice) |
88 | + error_message = "" | ||
83 | success_message = "Choice has more appearances than votes and skips" | 89 | success_message = "Choice has more appearances than votes and skips" |
84 | return [success_message, false] if @question_ids_with_votes_before_2010_02_17.include?(choice.question_id) | 90 | return [success_message, false] if @question_ids_with_votes_before_2010_02_17.include?(choice.question_id) |
85 | all_appearances = choice.appearances_on_the_left.count + choice.appearances_on_the_right.count | 91 | all_appearances = choice.appearances_on_the_left.count + choice.appearances_on_the_right.count |
@@ -181,6 +187,7 @@ namespace :test_api do | @@ -181,6 +187,7 @@ namespace :test_api do | ||
181 | end | 187 | end |
182 | 188 | ||
183 | def generated_prompts_on_each_side_are_equal(question) | 189 | def generated_prompts_on_each_side_are_equal(question) |
190 | + error_message = "" | ||
184 | success_message = "Number of generated prompts on left are equal to number generated on right" | 191 | success_message = "Number of generated prompts on left are equal to number generated on right" |
185 | generated_on_left = Choice.connection.select_one(" | 192 | generated_on_left = Choice.connection.select_one(" |
186 | SELECT COUNT(*) AS total FROM prompts | 193 | SELECT COUNT(*) AS total FROM prompts |
@@ -195,6 +202,7 @@ namespace :test_api do | @@ -195,6 +202,7 @@ namespace :test_api do | ||
195 | end | 202 | end |
196 | 203 | ||
197 | def check_scores_over_above_fifty(question) | 204 | def check_scores_over_above_fifty(question) |
205 | + error_message = "" | ||
198 | success_message = "Scores are distributed above and below 50" | 206 | success_message = "Scores are distributed above and below 50" |
199 | return [success_message, false] if @question_ids_with_votes_before_2010_02_17.include?(question.id) | 207 | return [success_message, false] if @question_ids_with_votes_before_2010_02_17.include?(question.id) |
200 | totals_lte_fifty = Choice.connection.select_one(" | 208 | totals_lte_fifty = Choice.connection.select_one(" |
@@ -213,6 +221,7 @@ namespace :test_api do | @@ -213,6 +221,7 @@ namespace :test_api do | ||
213 | end | 221 | end |
214 | 222 | ||
215 | def wins_and_losses_equals_two_times_vote_count(question) | 223 | def wins_and_losses_equals_two_times_vote_count(question) |
224 | + error_message = "" | ||
216 | success_message = "Wins and losses equals 2 times vote count" | 225 | success_message = "Wins and losses equals 2 times vote count" |
217 | return [success_message, false] if @question_ids_with_votes_before_2010_02_17.include?(question.id) | 226 | return [success_message, false] if @question_ids_with_votes_before_2010_02_17.include?(question.id) |
218 | totals = Question.connection.select_one(" | 227 | totals = Question.connection.select_one(" |
@@ -227,6 +236,7 @@ namespace :test_api do | @@ -227,6 +236,7 @@ namespace :test_api do | ||
227 | end | 236 | end |
228 | 237 | ||
229 | def wins_and_losses_is_even(question) | 238 | def wins_and_losses_is_even(question) |
239 | + error_message = "" | ||
230 | success_message = "Total Votes is even" | 240 | success_message = "Total Votes is even" |
231 | return [success_message, false] if @question_ids_with_votes_before_2010_02_17.include?(question.id) | 241 | return [success_message, false] if @question_ids_with_votes_before_2010_02_17.include?(question.id) |
232 | totals = Question.connection.select_one(" | 242 | totals = Question.connection.select_one(" |
@@ -241,6 +251,7 @@ namespace :test_api do | @@ -241,6 +251,7 @@ namespace :test_api do | ||
241 | end | 251 | end |
242 | 252 | ||
243 | def wins_and_losses_equals_two_times_wins(question) | 253 | def wins_and_losses_equals_two_times_wins(question) |
254 | + error_message = "" | ||
244 | success_message = "2 x Total Wins == Total Votes" | 255 | success_message = "2 x Total Wins == Total Votes" |
245 | return [success_message, false] if @question_ids_with_votes_before_2010_02_17.include?(question.id) | 256 | return [success_message, false] if @question_ids_with_votes_before_2010_02_17.include?(question.id) |
246 | totals = Question.connection.select_one(" | 257 | totals = Question.connection.select_one(" |
@@ -248,13 +259,14 @@ namespace :test_api do | @@ -248,13 +259,14 @@ namespace :test_api do | ||
248 | SUM(wins) AS total_wins, | 259 | SUM(wins) AS total_wins, |
249 | SUM(losses) AS total_losses FROM choices | 260 | SUM(losses) AS total_losses FROM choices |
250 | WHERE question_id = #{question.id}") | 261 | WHERE question_id = #{question.id}") |
251 | - if (2*totals["total_wins"] != totals["total"]) | 262 | + if (2*totals["total_wins"].to_i != totals["total"].to_i) |
252 | error_message = "Error: 2 x Total Wins != Total votes" | 263 | error_message = "Error: 2 x Total Wins != Total votes" |
253 | end | 264 | end |
254 | return error_message.blank? ? [success_message, false] : [error_message, true] | 265 | return error_message.blank? ? [success_message, false] : [error_message, true] |
255 | end | 266 | end |
256 | 267 | ||
257 | def answered_appearances_equals_votes_and_skips(question) | 268 | def answered_appearances_equals_votes_and_skips(question) |
269 | + error_message = "" | ||
258 | success_message = "All vote and skip objects have an associated appearance object" | 270 | success_message = "All vote and skip objects have an associated appearance object" |
259 | skip_appearances_count = Appearance.count( | 271 | skip_appearances_count = Appearance.count( |
260 | :conditions => ["skips.valid_record = 1 and appearances.question_id = ? AND answerable_id IS NOT NULL AND answerable_type = 'Skip'", question.id], | 272 | :conditions => ["skips.valid_record = 1 and appearances.question_id = ? AND answerable_id IS NOT NULL AND answerable_type = 'Skip'", question.id], |
@@ -273,6 +285,7 @@ namespace :test_api do | @@ -273,6 +285,7 @@ namespace :test_api do | ||
273 | end | 285 | end |
274 | 286 | ||
275 | def check_each_choice_appears_within_n_stddevs(question) | 287 | def check_each_choice_appears_within_n_stddevs(question) |
288 | + error_message = "" | ||
276 | success_message = "Each choice has appeared n times, where n falls within 6 stddevs of the mean number of appearances for a question " + | 289 | success_message = "Each choice has appeared n times, where n falls within 6 stddevs of the mean number of appearances for a question " + |
277 | "(Note: this applies only to seed choices (not user submitted) and choices currently marked active)" | 290 | "(Note: this applies only to seed choices (not user submitted) and choices currently marked active)" |
278 | 291 | ||
@@ -310,6 +323,7 @@ namespace :test_api do | @@ -310,6 +323,7 @@ namespace :test_api do | ||
310 | end | 323 | end |
311 | 324 | ||
312 | def check_each_choice_equally_likely_to_appear_left_or_right(question) | 325 | def check_each_choice_equally_likely_to_appear_left_or_right(question) |
326 | + error_message = "" | ||
313 | success_message = "All choices have equal probability of appearing on left or right (within error params)" | 327 | success_message = "All choices have equal probability of appearing on left or right (within error params)" |
314 | question.choices.each do |c| | 328 | question.choices.each do |c| |
315 | left_prompts_ids = c.prompts_on_the_left.ids_only | 329 | left_prompts_ids = c.prompts_on_the_left.ids_only |
@@ -430,6 +444,7 @@ namespace :test_api do | @@ -430,6 +444,7 @@ namespace :test_api do | ||
430 | 444 | ||
431 | def verify_range_of_choices_scores | 445 | def verify_range_of_choices_scores |
432 | bad_choices_count = Choice.count(:conditions => 'score < 0 OR score > 100') | 446 | bad_choices_count = Choice.count(:conditions => 'score < 0 OR score > 100') |
447 | + error_message = "" | ||
433 | success_message = "All choices have a score within 0-100" | 448 | success_message = "All choices have a score within 0-100" |
434 | if bad_choices_count > 0 | 449 | if bad_choices_count > 0 |
435 | error_message = "Some choices have a score less than 0 or greater than 100" | 450 | error_message = "Some choices have a score less than 0 or greater than 100" |