mirror of
https://github.com/Xevion/exercism.git
synced 2025-12-06 07:14:56 -06:00
54 lines
1.6 KiB
Python
54 lines
1.6 KiB
Python
import unittest
|
|
|
|
import hamming
|
|
|
|
|
|
# Tests adapted from `problem-specifications//canonical-data.json` @ v2.3.0
|
|
|
|
class HammingTest(unittest.TestCase):
|
|
|
|
def test_empty_strands(self):
|
|
self.assertEqual(hamming.distance("", ""), 0)
|
|
|
|
def test_single_letter_identical_strands(self):
|
|
self.assertEqual(hamming.distance("A", "A"), 0)
|
|
|
|
def test_single_letter_different_strands(self):
|
|
self.assertEqual(hamming.distance("G", "T"), 1)
|
|
|
|
def test_long_identical_strands(self):
|
|
self.assertEqual(hamming.distance("GGACTGAAATCTG", "GGACTGAAATCTG"), 0)
|
|
|
|
def test_long_different_strands(self):
|
|
self.assertEqual(hamming.distance("GGACGGATTCTG", "AGGACGGATTCT"), 9)
|
|
|
|
def test_disallow_first_strand_longer(self):
|
|
with self.assertRaisesWithMessage(ValueError):
|
|
hamming.distance("AATG", "AAA")
|
|
|
|
def test_disallow_second_strand_longer(self):
|
|
with self.assertRaisesWithMessage(ValueError):
|
|
hamming.distance("ATA", "AGTG")
|
|
|
|
def test_disallow_left_empty_strand(self):
|
|
with self.assertRaisesWithMessage(ValueError):
|
|
hamming.distance("", "G")
|
|
|
|
def test_disallow_right_empty_strand(self):
|
|
with self.assertRaisesWithMessage(ValueError):
|
|
hamming.distance("G", "")
|
|
|
|
# Utility functions
|
|
def setUp(self):
|
|
try:
|
|
self.assertRaisesRegex
|
|
except AttributeError:
|
|
self.assertRaisesRegex = self.assertRaisesRegexp
|
|
|
|
def assertRaisesWithMessage(self, exception):
|
|
return self.assertRaisesRegex(exception, r".+")
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|