From b4e3777ce91bba8b91c40e4086aaa3a39ecff0b4 Mon Sep 17 00:00:00 2001 From: Bethany Garcia Date: Tue, 21 May 2019 18:54:24 -0700 Subject: [PATCH 1/4] saddle-points: sync tests expected results with problem-specifications and update example solution. --- exercises/saddle-points/example.py | 18 +++++++-------- exercises/saddle-points/saddle_points_test.py | 22 +++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/exercises/saddle-points/example.py b/exercises/saddle-points/example.py index 76cbaedb16..6d2af0cb46 100644 --- a/exercises/saddle-points/example.py +++ b/exercises/saddle-points/example.py @@ -1,11 +1,11 @@ -def saddle_points(m): - if not m: - return set() - if any(len(r) != len(m[0]) for r in m): +def saddle_points(matrix): + if not matrix: + return [{}] + if any(len(row) != len(matrix[0]) for row in matrix): raise ValueError('irregular matrix') - mmax = [max(r) for r in m] - mmin = [min(c) for c in zip(*m)] - points = [(i+1, j+1) for i in range(len(m)) - for j in range(len(m[0])) if mmax[i] == mmin[j]] + mmax = [max(row) for row in matrix] + mmin = [min(col) for col in zip(*matrix)] + points = [{"row": index + 1, "column": col_index + 1} for index in range(len(matrix)) + for col_index in range(len(matrix[0])) if mmax[index] == mmin[col_index]] - return set(points) + return points or [{}] \ No newline at end of file diff --git a/exercises/saddle-points/saddle_points_test.py b/exercises/saddle-points/saddle_points_test.py index 636c5ec388..71d1fa74af 100644 --- a/exercises/saddle-points/saddle_points_test.py +++ b/exercises/saddle-points/saddle_points_test.py @@ -10,50 +10,50 @@ from saddle_points import saddle_points -# Tests adapted from `problem-specifications//canonical-data.json` @ v1.5.0 +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.6.0 class SaddlePointsTest(unittest.TestCase): def test_identify_single_saddle_point(self): matrix = [[9, 8, 7], [5, 3, 2], [6, 6, 7]] - self.assertEqual(saddle_points(matrix), set([(2, 1)])) + self.assertEqual(saddle_points(matrix), [{"row": 2, "column": 1}]) def test_empty_matrix_has_no_saddle_points(self): - self.assertEqual(saddle_points([]), set()) + self.assertEqual(saddle_points([]), [dict()]) def test_matrix_with_one_elem_has_single_saddle_point(self): matrix = [[1]] - self.assertEqual(saddle_points(matrix), set([(1, 1)])) + self.assertEqual(saddle_points(matrix), [{"row": 1, "column": 1}]) def test_identify_lack_of_saddle_points_when_there_are_none(self): matrix = [[1, 2, 3], [3, 1, 2], [2, 3, 1]] - self.assertEqual(saddle_points(matrix), set()) + self.assertEqual(saddle_points(matrix), [dict()]) def test_identify_multiple_saddle_points_in_column(self): matrix = [[4, 5, 4], [3, 5, 5], [1, 5, 4]] - expected = set([(1, 2), (2, 2), (3, 2)]) + expected = [{"row": 1, "column": 2}, {"row": 2, "column": 2}, {"row": 3, "column": 2}] self.assertEqual(saddle_points(matrix), expected) def test_identify_multiple_saddle_points_in_row(self): matrix = [[6, 7, 8], [5, 5, 5], [7, 5, 6]] - expected = set([(2, 1), (2, 2), (2, 3)]) + expected = [{"row": 2, "column": 1}, {"row": 2, "column": 2}, {"row": 2, "column": 3}] self.assertEqual(saddle_points(matrix), expected) def test_identify_saddle_point_in_bottom_right_corner(self): matrix = [[8, 7, 9], [6, 7, 6], [3, 2, 5]] - expected = set([(3, 3)]) + expected = [{"row": 3, "column": 3}] self.assertEqual(saddle_points(matrix), expected) def test_non_square_matrix_with_2_saddle_points(self): matrix = [[3, 1, 3], [3, 2, 4]] - self.assertEqual(saddle_points(matrix), set([(1, 3), (1, 1)])) + self.assertEqual(saddle_points(matrix), [{"row": 1, "column": 1}, {"row": 1, "column": 3}]) def test_single_column_matrix_has_saddle_point_min_value(self): matrix = [[2], [1], [4], [1]] - self.assertEqual(saddle_points(matrix), set([(2, 1), (4, 1)])) + self.assertEqual(saddle_points(matrix), [{"row": 2, "column": 1}, {"row": 4, "column": 1}]) def test_single_row_matrix_has_saddle_point_in_max_value(self): matrix = [[2, 5, 3, 5]] - self.assertEqual(saddle_points(matrix), set([(1, 2), (1, 4)])) + self.assertEqual(saddle_points(matrix), [{"row": 1, "column": 2}, {"row": 1, "column": 4}]) # Additional tests for this track From bcdd67f723efb01867f4d5681beb0f51f8e322b7 Mon Sep 17 00:00:00 2001 From: Bethany Garcia Date: Tue, 21 May 2019 19:09:15 -0700 Subject: [PATCH 2/4] Revert "saddle-points: sync tests expected results with problem-specifications and update example solution." This reverts commit b4e3777ce91bba8b91c40e4086aaa3a39ecff0b4. Wanted this in it's own branch. --- exercises/saddle-points/example.py | 18 +++++++-------- exercises/saddle-points/saddle_points_test.py | 22 +++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/exercises/saddle-points/example.py b/exercises/saddle-points/example.py index 6d2af0cb46..76cbaedb16 100644 --- a/exercises/saddle-points/example.py +++ b/exercises/saddle-points/example.py @@ -1,11 +1,11 @@ -def saddle_points(matrix): - if not matrix: - return [{}] - if any(len(row) != len(matrix[0]) for row in matrix): +def saddle_points(m): + if not m: + return set() + if any(len(r) != len(m[0]) for r in m): raise ValueError('irregular matrix') - mmax = [max(row) for row in matrix] - mmin = [min(col) for col in zip(*matrix)] - points = [{"row": index + 1, "column": col_index + 1} for index in range(len(matrix)) - for col_index in range(len(matrix[0])) if mmax[index] == mmin[col_index]] + mmax = [max(r) for r in m] + mmin = [min(c) for c in zip(*m)] + points = [(i+1, j+1) for i in range(len(m)) + for j in range(len(m[0])) if mmax[i] == mmin[j]] - return points or [{}] \ No newline at end of file + return set(points) diff --git a/exercises/saddle-points/saddle_points_test.py b/exercises/saddle-points/saddle_points_test.py index 71d1fa74af..636c5ec388 100644 --- a/exercises/saddle-points/saddle_points_test.py +++ b/exercises/saddle-points/saddle_points_test.py @@ -10,50 +10,50 @@ from saddle_points import saddle_points -# Tests adapted from `problem-specifications//canonical-data.json` @ v1.6.0 +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.5.0 class SaddlePointsTest(unittest.TestCase): def test_identify_single_saddle_point(self): matrix = [[9, 8, 7], [5, 3, 2], [6, 6, 7]] - self.assertEqual(saddle_points(matrix), [{"row": 2, "column": 1}]) + self.assertEqual(saddle_points(matrix), set([(2, 1)])) def test_empty_matrix_has_no_saddle_points(self): - self.assertEqual(saddle_points([]), [dict()]) + self.assertEqual(saddle_points([]), set()) def test_matrix_with_one_elem_has_single_saddle_point(self): matrix = [[1]] - self.assertEqual(saddle_points(matrix), [{"row": 1, "column": 1}]) + self.assertEqual(saddle_points(matrix), set([(1, 1)])) def test_identify_lack_of_saddle_points_when_there_are_none(self): matrix = [[1, 2, 3], [3, 1, 2], [2, 3, 1]] - self.assertEqual(saddle_points(matrix), [dict()]) + self.assertEqual(saddle_points(matrix), set()) def test_identify_multiple_saddle_points_in_column(self): matrix = [[4, 5, 4], [3, 5, 5], [1, 5, 4]] - expected = [{"row": 1, "column": 2}, {"row": 2, "column": 2}, {"row": 3, "column": 2}] + expected = set([(1, 2), (2, 2), (3, 2)]) self.assertEqual(saddle_points(matrix), expected) def test_identify_multiple_saddle_points_in_row(self): matrix = [[6, 7, 8], [5, 5, 5], [7, 5, 6]] - expected = [{"row": 2, "column": 1}, {"row": 2, "column": 2}, {"row": 2, "column": 3}] + expected = set([(2, 1), (2, 2), (2, 3)]) self.assertEqual(saddle_points(matrix), expected) def test_identify_saddle_point_in_bottom_right_corner(self): matrix = [[8, 7, 9], [6, 7, 6], [3, 2, 5]] - expected = [{"row": 3, "column": 3}] + expected = set([(3, 3)]) self.assertEqual(saddle_points(matrix), expected) def test_non_square_matrix_with_2_saddle_points(self): matrix = [[3, 1, 3], [3, 2, 4]] - self.assertEqual(saddle_points(matrix), [{"row": 1, "column": 1}, {"row": 1, "column": 3}]) + self.assertEqual(saddle_points(matrix), set([(1, 3), (1, 1)])) def test_single_column_matrix_has_saddle_point_min_value(self): matrix = [[2], [1], [4], [1]] - self.assertEqual(saddle_points(matrix), [{"row": 2, "column": 1}, {"row": 4, "column": 1}]) + self.assertEqual(saddle_points(matrix), set([(2, 1), (4, 1)])) def test_single_row_matrix_has_saddle_point_in_max_value(self): matrix = [[2, 5, 3, 5]] - self.assertEqual(saddle_points(matrix), [{"row": 1, "column": 2}, {"row": 1, "column": 4}]) + self.assertEqual(saddle_points(matrix), set([(1, 2), (1, 4)])) # Additional tests for this track From 65e1e836db42af965488dd3249035e9144857576 Mon Sep 17 00:00:00 2001 From: Bethany Garcia Date: Wed, 22 May 2019 18:40:11 -0700 Subject: [PATCH 3/4] Bob: sync expected test results and input data with problem-specifications. --- exercises/bob/bob.py | 2 +- exercises/bob/bob_test.py | 57 ++++++++++++++++++++------------------- exercises/bob/example.py | 24 ++++++++--------- 3 files changed, 42 insertions(+), 41 deletions(-) diff --git a/exercises/bob/bob.py b/exercises/bob/bob.py index 0c4235d479..94a7315112 100644 --- a/exercises/bob/bob.py +++ b/exercises/bob/bob.py @@ -1,2 +1,2 @@ -def hey(phrase): +def response(hey_bob): pass diff --git a/exercises/bob/bob_test.py b/exercises/bob/bob_test.py index 9647173db5..972035b949 100644 --- a/exercises/bob/bob_test.py +++ b/exercises/bob/bob_test.py @@ -1,100 +1,101 @@ import unittest -from bob import hey +from bob import response -# Tests adapted from `problem-specifications//canonical-data.json` @ v1.4.0 +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.5.0 class BobTest(unittest.TestCase): def test_stating_something(self): - self.assertEqual(hey("Tom-ay-to, tom-aaaah-to."), "Whatever.") + self.assertEqual(response("Tom-ay-to, tom-aaaah-to."), "Whatever.") def test_shouting(self): - self.assertEqual(hey("WATCH OUT!"), "Whoa, chill out!") + self.assertEqual(response("WATCH OUT!"), "Whoa, chill out!") def test_shouting_gibberish(self): - self.assertEqual(hey("FCECDFCAAB"), "Whoa, chill out!") + self.assertEqual(response("FCECDFCAAB"), "Whoa, chill out!") def test_asking_a_question(self): self.assertEqual( - hey("Does this cryogenic chamber make me look fat?"), "Sure.") + response("Does this cryogenic chamber make me look fat?"), "Sure.") def test_asking_a_numeric_question(self): - self.assertEqual(hey("You are, what, like 15?"), "Sure.") + self.assertEqual(response("You are, what, like 15?"), "Sure.") def test_asking_gibberish(self): - self.assertEqual(hey("fffbbcbeab?"), "Sure.") + self.assertEqual(response("fffbbcbeab?"), "Sure.") def test_talking_forcefully(self): self.assertEqual( - hey("Let's go make out behind the gym!"), "Whatever.") + response("Let's go make out behind the gym!"), "Whatever.") def test_using_acronyms_in_regular_speech(self): self.assertEqual( - hey("It's OK if you don't want to go to the DMV."), + response("It's OK if you don't want to go to the DMV."), "Whatever.") def test_forceful_question(self): self.assertEqual( - hey("WHAT THE HELL WERE YOU THINKING?"), + response("WHAT THE HELL WERE YOU THINKING?"), "Calm down, I know what I'm doing!" ) def test_shouting_numbers(self): - self.assertEqual(hey("1, 2, 3 GO!"), "Whoa, chill out!") + self.assertEqual(response("1, 2, 3 GO!"), "Whoa, chill out!") def test_no_letters(self): - self.assertEqual(hey("1, 2, 3"), "Whatever.") + self.assertEqual(response("1, 2, 3"), "Whatever.") def test_question_with_no_letters(self): - self.assertEqual(hey("4?"), "Sure.") + self.assertEqual(response("4?"), "Sure.") def test_shouting_with_special_characters(self): self.assertEqual( - hey("ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!"), + response("ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!"), "Whoa, chill out!") def test_shouting_with_no_exclamation_mark(self): - self.assertEqual(hey("I HATE THE DMV"), "Whoa, chill out!") + self.assertEqual(response("I HATE THE DMV"), "Whoa, chill out!") def test_statement_containing_question_mark(self): self.assertEqual( - hey("Ending with ? means a question."), "Whatever.") + response("Ending with ? means a question."), "Whatever.") def test_non_letters_with_question(self): - self.assertEqual(hey(":) ?"), "Sure.") + self.assertEqual(response(":) ?"), "Sure.") def test_prattling_on(self): self.assertEqual( - hey("Wait! Hang on. Are you going to be OK?"), "Sure.") + response("Wait! Hang on. Are you going to be OK?"), "Sure.") def test_silence(self): - self.assertEqual(hey(""), "Fine. Be that way!") + self.assertEqual(response(""), "Fine. Be that way!") def test_prolonged_silence(self): - self.assertEqual(hey(" "), "Fine. Be that way!") + self.assertEqual(response(" "), "Fine. Be that way!") def test_alternate_silence(self): - self.assertEqual(hey("\t\t\t\t\t\t\t\t\t\t"), "Fine. Be that way!") + self.assertEqual(response("\t\t\t\t\t\t\t\t\t\t"), + "Fine. Be that way!") def test_multiple_line_question(self): self.assertEqual( - hey("\nDoes this cryogenic chamber make me look fat?\nNo."), - "Whatever.") + response("\nDoes this cryogenic chamber make me look fat?\n" + "No."), "Whatever.") def test_starting_with_whitespace(self): - self.assertEqual(hey(" hmmmmmmm..."), "Whatever.") + self.assertEqual(response(" hmmmmmmm..."), "Whatever.") def test_ending_with_whitespace(self): self.assertEqual( - hey("Okay if like my spacebar quite a bit? "), "Sure.") + response("Okay if like my spacebar quite a bit? "), "Sure.") def test_other_whitespace(self): - self.assertEqual(hey("\n\r \t"), "Fine. Be that way!") + self.assertEqual(response("\n\r \t"), "Fine. Be that way!") def test_non_question_ending_with_whitespace(self): self.assertEqual( - hey("This is a statement ending with whitespace "), + response("This is a statement ending with whitespace "), "Whatever.") diff --git a/exercises/bob/example.py b/exercises/bob/example.py index 5932176167..630ccccc61 100644 --- a/exercises/bob/example.py +++ b/exercises/bob/example.py @@ -1,26 +1,26 @@ -def hey(stimulus): - stimulus = stimulus.strip() +def response(hey_bob): + hey_bob = hey_bob.strip() - if _is_silence(stimulus): + if _is_silence(hey_bob): return 'Fine. Be that way!' - if _is_shouting(stimulus): - if _is_question(stimulus): + if _is_shouting(hey_bob): + if _is_question(hey_bob): return "Calm down, I know what I'm doing!" else: return 'Whoa, chill out!' - elif _is_question(stimulus): + elif _is_question(hey_bob): return 'Sure.' else: return 'Whatever.' -def _is_silence(stimulus): - return stimulus == '' +def _is_silence(hey_bob): + return hey_bob == '' -def _is_shouting(stimulus): - return stimulus.isupper() +def _is_shouting(hey_bob): + return hey_bob.isupper() -def _is_question(stimulus): - return stimulus.endswith('?') +def _is_question(hey_bob): + return hey_bob.endswith('?') From db4a0f29c72d1833c5fa2b9ba7a4fd5dd14a66bf Mon Sep 17 00:00:00 2001 From: Bethany Garcia Date: Wed, 22 May 2019 19:42:03 -0700 Subject: [PATCH 4/4] Reverted cannonical-data.json version number to 1.4.0 to match problem-specification. --- exercises/bob/bob_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/bob/bob_test.py b/exercises/bob/bob_test.py index 972035b949..6c032c6174 100644 --- a/exercises/bob/bob_test.py +++ b/exercises/bob/bob_test.py @@ -3,7 +3,7 @@ from bob import response -# Tests adapted from `problem-specifications//canonical-data.json` @ v1.5.0 +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.4.0 class BobTest(unittest.TestCase): def test_stating_something(self):