unittest
is a built-in Python module that can perform unit testing in an object-oriented wayunittest - Unit testing framework - Python 3.11.0 documentation
unittest
supports the following concepts:
import dna
import unittest
class TestDna(unittest.TestCase):
@classmethod
def setUpClass(cls):
print()
print("setUpClass() called")
print()
@classmethod
def tearDownClass(cls):
print()
print("tearDown() called")
print()
def setUp(self):
print()
print("setUp() called")
print()
def tearDown(self):
print()
print("tearDown() called")
print()
def test_find_0_(self):
seq = list("AAAGTTAAATAATAAATAGGTGAA")
seq_to_find = list("AAA")
matches_sub = dna.find(seq, seq_to_find)
matches_ans = [0, 6, 13]
self.assertEqual(matches_sub, matches_ans)
def test_find_1_(self):
seq = list("AAAGTTAAATAATAAATAGGTGAAA")
seq_to_find = list("AAA")
matches_sub = dna.find(seq, seq_to_find)
matches_ans = [0, 6, 13, 22]
self.assertEqual(matches_sub, matches_ans)
def suit():
suite = unittest.TestSuite()
suite.addTest(TestDna("test_find_0_"))
suite.addTest(TestDna("test_find_1_"))
return suite
def main():
runner = unittest.TextTestRunner(verbosity=2, descriptions=1)
results = runner.run(suite())
if __name__ == "__main__":
main()
### terminal feedback from above code
setUpClass() called
test_find_0_(__main__.TestDna) ...
setUp() called
test_find_0_ running...
tearDown() called
ok
test_find_1_(__main__.TestDna) ...
setUp() called
test_find_1_ running...
tearDown() called
ok
tearDownClass() called
<aside> 💡 Algorithms are methods for solving problems that can be implemented on a computer
</aside>