-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_box.py
33 lines (25 loc) · 878 Bytes
/
make_box.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
#!/usr/bin/env python3
# -*- coding: utf8 -*-
import unittest
# Weekly Challenge June 25, 2024
# Making a box
# Create a function that creates a box based on dimension n.
def make_box(n: int) -> list[str]:
"""
Creates a box based on dimension n.
:param n: The dimension of the box.
:returns: A list representing the box.
"""
if n == 1:
return ["#"]
top_bottom = "#" * n
middle = "#" + " " * (n - 2) + "#"
return [top_bottom] + [middle] * (n - 2) + [top_bottom]
class TestMakeBox(unittest.TestCase):
def test_make_box(self) -> None:
self.assertEqual(make_box(5), ["#####", "# #", "# #", "# #", "#####"])
self.assertEqual(make_box(3), ["###", "# #", "###"])
self.assertEqual(make_box(2), ["##", "##"])
self.assertEqual(make_box(1), ["#"])
if __name__ == "__main__":
unittest.main()