Files
python/exercises/practice/hamming/hamming_test.py

49 lines
1.4 KiB
Python
Raw Normal View History

2014-04-07 22:32:31 -03:00
import unittest
from hamming import (
distance,
)
2020-10-15 12:46:24 -04:00
# Tests adapted from `problem-specifications//canonical-data.json`
2017-03-20 16:42:22 +01:00
2014-04-07 22:32:31 -03:00
class HammingTest(unittest.TestCase):
def test_empty_strands(self):
self.assertEqual(distance("", ""), 0)
def test_single_letter_identical_strands(self):
self.assertEqual(distance("A", "A"), 0)
2014-04-07 22:32:31 -03:00
def test_single_letter_different_strands(self):
self.assertEqual(distance("G", "T"), 1)
2014-04-07 22:32:31 -03:00
def test_long_identical_strands(self):
self.assertEqual(distance("GGACTGAAATCTG", "GGACTGAAATCTG"), 0)
def test_long_different_strands(self):
self.assertEqual(distance("GGACGGATTCTG", "AGGACGGATTCT"), 9)
def test_disallow_first_strand_longer(self):
with self.assertRaisesWithMessage(ValueError):
distance("AATG", "AAA")
def test_disallow_second_strand_longer(self):
with self.assertRaisesWithMessage(ValueError):
distance("ATA", "AGTG")
2014-04-07 22:32:31 -03:00
def test_disallow_left_empty_strand(self):
with self.assertRaisesWithMessage(ValueError):
distance("", "G")
def test_disallow_right_empty_strand(self):
with self.assertRaisesWithMessage(ValueError):
distance("G", "")
# Utility functions
def assertRaisesWithMessage(self, exception):
return self.assertRaisesRegex(exception, r".+")
2014-04-07 22:32:31 -03:00
if __name__ == "__main__":
2014-04-07 22:32:31 -03:00
unittest.main()