This commit is contained in:
Xevion
2019-07-13 04:18:06 -05:00
parent d558cf2d6c
commit 266e06add5
29 changed files with 656 additions and 1 deletions

View File

@@ -0,0 +1,53 @@
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()