Add support for parametrized blocks

- Modify action to support input of block string
- Modify make graph function to support parametrized blocks
- Add tests for parametrized blocks
- Update README with new issue
- Fix some format errors and typos
This commit is contained in:
Malcolm Davis
2020-09-13 00:42:18 -06:00
committed by Malcolm Davis Steele
parent ec79c6dacb
commit c5aaa5ad5d
4 changed files with 125 additions and 70 deletions

View File

@@ -3,26 +3,47 @@ Tests for the main.py
'''
from main import make_graph
import unittest
import os
class TestMain(unittest.TestCase):
def test_make_graph(self):
'''Tests the make_graph function'''
def test(percent: float, result: str):
self.assertEqual(make_graph(percent), result, f"{percent}% should return {result}")
test(0, "░░░░░░░░░░░░░░░░░░░░░░░░░")
test(100, "█████████████████████████")
test(50, "████████████▒░░░░░░░░░░░░")
test(50.001, "████████████▓░░░░░░░░░░░░")
test(25, "██████▒░░░░░░░░░░░░░░░░░░")
test(75, "██████████████████▓░░░░░░")
test(3.14, "▓░░░░░░░░░░░░░░░░░░░░░░░░")
test(9.901, "██▒░░░░░░░░░░░░░░░░░░░░░░")
test(87.334, "██████████████████████░░░")
test(87.333, "█████████████████████▓░░░")
test(4.666, "░░░░░░░░░░░░░░░░░░░░░░░░")
test(4.667, "█▒░░░░░░░░░░░░░░░░░░░░░░")
def test(percent: float, block: str, result: str):
self.assertEqual(make_graph(percent, block), result,
f"{percent}% should return {result}")
blocks = ["░▒▓█", "⚪⚫"]
percents = [0, 100, 50, 50.001, 25, 75, 3.14,
9.901, 87.334, 87.333, 4.666, 4.667]
graphGroup = [["░░░░░░░░░░░░░░░░░░░░░░░░░",
"█████████████████████████",
"████████████▒░░░░░░░░░░░░",
"████████████▓░░░░░░░░░░░░",
"██████▒░░░░░░░░░░░░░░░░░░",
"██████████████████▓░░░░░░",
"░░░░░░░░░░░░░░░░░░░░░░░░",
"▒░░░░░░░░░░░░░░░░░░░░░░",
"██████████████████████░░░",
"█████████████████████▓░░░",
"█░░░░░░░░░░░░░░░░░░░░░░░░",
"█▒░░░░░░░░░░░░░░░░░░░░░░░"],
["⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪",
"⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫",
"⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪",
"⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪",
"⚫⚫⚫⚫⚫⚫⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪",
"⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚪⚪⚪⚪⚪",
"⚫⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪",
"⚫⚫⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪",
"⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚪",
"⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚪⚪",
"⚫⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪",
"⚫⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪"]]
for i, graphs in enumerate(graphGroup):
os.environ["INPUT_BLOCKS"] = blocks[i]
for j, graph in enumerate(graphs):
test(percents[j], blocks[i], graph)
if __name__ == '__main__':