-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathrectangles_test.py
102 lines (85 loc) · 2.93 KB
/
rectangles_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# These tests are auto-generated with test data from:
# https://github.com/exercism/problem-specifications/tree/main/exercises/rectangles/canonical-data.json
# File last updated on 2023-07-19
import unittest
from rectangles import (
rectangles,
)
class RectanglesTest(unittest.TestCase):
def test_no_rows(self):
self.assertEqual(rectangles([]), 0)
def test_no_columns(self):
self.assertEqual(rectangles([""]), 0)
def test_no_rectangles(self):
self.assertEqual(rectangles([" "]), 0)
def test_one_rectangle(self):
self.assertEqual(rectangles(["+-+", "| |", "+-+"]), 1)
def test_two_rectangles_without_shared_parts(self):
self.assertEqual(rectangles([" +-+", " | |", "+-+-+", "| | ", "+-+ "]), 2)
def test_five_rectangles_with_shared_parts(self):
self.assertEqual(rectangles([" +-+", " | |", "+-+-+", "| | |", "+-+-+"]), 5)
def test_rectangle_of_height_1_is_counted(self):
self.assertEqual(rectangles(["+--+", "+--+"]), 1)
def test_rectangle_of_width_1_is_counted(self):
self.assertEqual(rectangles(["++", "||", "++"]), 1)
def test_1x1_square_is_counted(self):
self.assertEqual(rectangles(["++", "++"]), 1)
def test_only_complete_rectangles_are_counted(self):
self.assertEqual(rectangles([" +-+", " |", "+-+-+", "| | -", "+-+-+"]), 1)
def test_rectangles_can_be_of_different_sizes(self):
self.assertEqual(
rectangles(
[
"+------+----+",
"| | |",
"+---+--+ |",
"| | |",
"+---+-------+",
]
),
3,
)
def test_corner_is_required_for_a_rectangle_to_be_complete(self):
self.assertEqual(
rectangles(
[
"+------+----+",
"| | |",
"+------+ |",
"| | |",
"+---+-------+",
]
),
2,
)
def test_large_input_with_many_rectangles(self):
self.assertEqual(
rectangles(
[
"+---+--+----+",
"| +--+----+",
"+---+--+ |",
"| +--+----+",
"+---+--+--+-+",
"+---+--+--+-+",
"+------+ | |",
" +-+",
]
),
60,
)
def test_rectangles_must_have_four_sides(self):
self.assertEqual(
rectangles(
[
"+-+ +-+",
"| | | |",
"+-+-+-+",
" | | ",
"+-+-+-+",
"| | | |",
"+-+ +-+",
]
),
5,
)