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 04f1a86838fd79da1910bb67170cb7cd17497e6f Mon Sep 17 00:00:00 2001 From: Bethany Garcia Date: Wed, 22 May 2019 16:37:16 -0700 Subject: [PATCH 3/4] Binary-search: sync expected test inputs with problem-specifications --- exercises/binary-search/binary_search.py | 2 +- exercises/binary-search/binary_search_test.py | 27 +++++++++---------- exercises/binary-search/example.py | 2 +- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/exercises/binary-search/binary_search.py b/exercises/binary-search/binary_search.py index 1bdb370a3b..7876b94e2c 100644 --- a/exercises/binary-search/binary_search.py +++ b/exercises/binary-search/binary_search.py @@ -1,2 +1,2 @@ -def binary_search(list_of_numbers, number): +def find(search_list, value): pass diff --git a/exercises/binary-search/binary_search_test.py b/exercises/binary-search/binary_search_test.py index d187ba97af..11e3482321 100644 --- a/exercises/binary-search/binary_search_test.py +++ b/exercises/binary-search/binary_search_test.py @@ -1,52 +1,51 @@ import unittest -from binary_search import binary_search +from binary_search import find -# Tests adapted from `problem-specifications//canonical-data.json` @ v1.3.0 +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.4.0 class BinarySearchTest(unittest.TestCase): def test_finds_value_in_array_with_one_element(self): - self.assertEqual(binary_search([6], 6), 0) + self.assertEqual(find([6], 6), 0) def test_finds_value_in_middle_of_array(self): - self.assertEqual(binary_search([1, 3, 4, 6, 8, 9, 11], 6), 3) + self.assertEqual(find([1, 3, 4, 6, 8, 9, 11], 6), 3) def test_finds_value_at_beginning_of_array(self): - self.assertEqual(binary_search([1, 3, 4, 6, 8, 9, 11], 1), 0) + self.assertEqual(find([1, 3, 4, 6, 8, 9, 11], 1), 0) def test_finds_value_at_end_of_array(self): - self.assertEqual(binary_search([1, 3, 4, 6, 8, 9, 11], 11), 6) + self.assertEqual(find([1, 3, 4, 6, 8, 9, 11], 11), 6) def test_finds_value_in_array_of_odd_length(self): self.assertEqual( - binary_search([1, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 634], - 144), 9) + find([1, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 634], 144), 9) def test_finds_value_in_array_of_even_length(self): self.assertEqual( - binary_search([1, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377], 21), + find([1, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377], 21), 5) def test_identifies_value_missing(self): with self.assertRaisesWithMessage(ValueError): - binary_search([1, 3, 4, 6, 8, 9, 11], 7) + find([1, 3, 4, 6, 8, 9, 11], 7) def test_value_smaller_than_arrays_minimum(self): with self.assertRaisesWithMessage(ValueError): - binary_search([1, 3, 4, 6, 8, 9, 11], 0) + find([1, 3, 4, 6, 8, 9, 11], 0) def test_value_larger_than_arrays_maximum(self): with self.assertRaisesWithMessage(ValueError): - binary_search([1, 3, 4, 6, 8, 9, 11], 13) + find([1, 3, 4, 6, 8, 9, 11], 13) def test_empty_array(self): with self.assertRaisesWithMessage(ValueError): - binary_search([], 1) + find([], 1) def test_nothing_is_found_when_left_and_right_bounds_cross(self): with self.assertRaisesWithMessage(ValueError): - binary_search([1, 2], 0) + find([1, 2], 0) # Utility functions def setUp(self): diff --git a/exercises/binary-search/example.py b/exercises/binary-search/example.py index 0b8f73a3c7..0643ee62c0 100644 --- a/exercises/binary-search/example.py +++ b/exercises/binary-search/example.py @@ -1,4 +1,4 @@ -def binary_search(search_list, value): +def find(search_list, value): low = 0 high = len(search_list) - 1 while low <= high: From 7940afc8c6c3eeb7e631723c69bc637a3efcb2dd Mon Sep 17 00:00:00 2001 From: Bethany Garcia Date: Wed, 22 May 2019 19:45:55 -0700 Subject: [PATCH 4/4] Reverted cannonical-data.json version number to 1.3.0 to match problem-specification. --- exercises/binary-search/binary_search_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/binary-search/binary_search_test.py b/exercises/binary-search/binary_search_test.py index 11e3482321..1d8f44e73a 100644 --- a/exercises/binary-search/binary_search_test.py +++ b/exercises/binary-search/binary_search_test.py @@ -2,7 +2,7 @@ from binary_search import find -# Tests adapted from `problem-specifications//canonical-data.json` @ v1.4.0 +# Tests adapted from `problem-specifications//canonical-data.json` @ v1.3.0 class BinarySearchTest(unittest.TestCase):