2023-07-15 15:27:31 -07:00
|
|
|
# These tests are auto-generated with test data from:
|
|
|
|
|
# https://github.com/exercism/problem-specifications/tree/main/exercises/rectangles/canonical-data.json
|
2023-07-21 16:54:40 -07:00
|
|
|
# File last updated on 2023-07-19
|
2023-07-15 15:27:31 -07:00
|
|
|
|
2015-09-03 13:27:42 -04:00
|
|
|
import unittest
|
|
|
|
|
|
2021-01-31 16:49:12 -05:00
|
|
|
from rectangles import (
|
|
|
|
|
rectangles,
|
|
|
|
|
)
|
2015-09-03 13:27:42 -04:00
|
|
|
|
2019-10-31 12:43:35 +01:00
|
|
|
|
2018-06-13 09:12:09 -04:00
|
|
|
class RectanglesTest(unittest.TestCase):
|
2017-04-08 08:23:43 +02:00
|
|
|
def test_no_rows(self):
|
2019-06-11 10:54:04 -07:00
|
|
|
self.assertEqual(rectangles([]), 0)
|
2015-11-08 01:31:17 +01:00
|
|
|
|
2017-04-08 08:23:43 +02:00
|
|
|
def test_no_columns(self):
|
2019-10-31 12:43:35 +01:00
|
|
|
self.assertEqual(rectangles([""]), 0)
|
2015-09-03 13:27:42 -04:00
|
|
|
|
2017-04-08 08:23:43 +02:00
|
|
|
def test_no_rectangles(self):
|
2019-10-31 12:43:35 +01:00
|
|
|
self.assertEqual(rectangles([" "]), 0)
|
2015-09-03 13:27:42 -04:00
|
|
|
|
2015-11-08 01:31:17 +01:00
|
|
|
def test_one_rectangle(self):
|
2019-10-31 12:43:35 +01:00
|
|
|
self.assertEqual(rectangles(["+-+", "| |", "+-+"]), 1)
|
2015-09-03 13:27:42 -04:00
|
|
|
|
2017-04-08 08:23:43 +02:00
|
|
|
def test_two_rectangles_without_shared_parts(self):
|
2019-10-31 12:43:35 +01:00
|
|
|
self.assertEqual(rectangles([" +-+", " | |", "+-+-+", "| | ", "+-+ "]), 2)
|
2015-09-03 13:27:42 -04:00
|
|
|
|
2017-04-08 08:23:43 +02:00
|
|
|
def test_five_rectangles_with_shared_parts(self):
|
2019-10-31 12:43:35 +01:00
|
|
|
self.assertEqual(rectangles([" +-+", " | |", "+-+-+", "| | |", "+-+-+"]), 5)
|
2015-09-03 13:27:42 -04:00
|
|
|
|
2017-04-08 08:23:43 +02:00
|
|
|
def test_rectangle_of_height_1_is_counted(self):
|
2019-10-31 12:43:35 +01:00
|
|
|
self.assertEqual(rectangles(["+--+", "+--+"]), 1)
|
2017-04-08 08:23:43 +02:00
|
|
|
|
|
|
|
|
def test_rectangle_of_width_1_is_counted(self):
|
2019-10-31 12:43:35 +01:00
|
|
|
self.assertEqual(rectangles(["++", "||", "++"]), 1)
|
2017-04-08 08:23:43 +02:00
|
|
|
|
|
|
|
|
def test_1x1_square_is_counted(self):
|
2019-10-31 12:43:35 +01:00
|
|
|
self.assertEqual(rectangles(["++", "++"]), 1)
|
2017-04-08 08:23:43 +02:00
|
|
|
|
|
|
|
|
def test_only_complete_rectangles_are_counted(self):
|
2019-10-31 12:43:35 +01:00
|
|
|
self.assertEqual(rectangles([" +-+", " |", "+-+-+", "| | -", "+-+-+"]), 1)
|
2015-09-03 13:27:42 -04:00
|
|
|
|
2017-04-08 08:23:43 +02:00
|
|
|
def test_rectangles_can_be_of_different_sizes(self):
|
2019-10-31 12:43:35 +01:00
|
|
|
self.assertEqual(
|
|
|
|
|
rectangles(
|
|
|
|
|
[
|
|
|
|
|
"+------+----+",
|
|
|
|
|
"| | |",
|
|
|
|
|
"+---+--+ |",
|
|
|
|
|
"| | |",
|
|
|
|
|
"+---+-------+",
|
|
|
|
|
]
|
|
|
|
|
),
|
|
|
|
|
3,
|
|
|
|
|
)
|
2015-09-03 13:27:42 -04:00
|
|
|
|
2017-04-08 08:23:43 +02:00
|
|
|
def test_corner_is_required_for_a_rectangle_to_be_complete(self):
|
2019-10-31 12:43:35 +01:00
|
|
|
self.assertEqual(
|
|
|
|
|
rectangles(
|
|
|
|
|
[
|
|
|
|
|
"+------+----+",
|
|
|
|
|
"| | |",
|
|
|
|
|
"+------+ |",
|
|
|
|
|
"| | |",
|
|
|
|
|
"+---+-------+",
|
|
|
|
|
]
|
|
|
|
|
),
|
|
|
|
|
2,
|
|
|
|
|
)
|
2015-09-03 13:27:42 -04:00
|
|
|
|
2017-04-08 08:23:43 +02:00
|
|
|
def test_large_input_with_many_rectangles(self):
|
2019-10-31 12:43:35 +01:00
|
|
|
self.assertEqual(
|
|
|
|
|
rectangles(
|
|
|
|
|
[
|
|
|
|
|
"+---+--+----+",
|
|
|
|
|
"| +--+----+",
|
|
|
|
|
"+---+--+ |",
|
|
|
|
|
"| +--+----+",
|
|
|
|
|
"+---+--+--+-+",
|
|
|
|
|
"+---+--+--+-+",
|
|
|
|
|
"+------+ | |",
|
|
|
|
|
" +-+",
|
|
|
|
|
]
|
|
|
|
|
),
|
|
|
|
|
60,
|
|
|
|
|
)
|
|
|
|
|
|
2022-12-02 19:29:26 +01:00
|
|
|
def test_rectangles_must_have_four_sides(self):
|
|
|
|
|
self.assertEqual(
|
|
|
|
|
rectangles(
|
|
|
|
|
[
|
|
|
|
|
"+-+ +-+",
|
|
|
|
|
"| | | |",
|
|
|
|
|
"+-+-+-+",
|
|
|
|
|
" | | ",
|
|
|
|
|
"+-+-+-+",
|
|
|
|
|
"| | | |",
|
|
|
|
|
"+-+ +-+",
|
|
|
|
|
]
|
|
|
|
|
),
|
|
|
|
|
5,
|
|
|
|
|
)
|