This repository was archived by the owner on Mar 15, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhamming_test.py
More file actions
46 lines (31 loc) · 1.36 KB
/
Copy pathhamming_test.py
File metadata and controls
46 lines (31 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import unittest
from hamming import distance
# Tests adapted from `problem-specifications//canonical-data.json`
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)
def test_single_letter_different_strands(self):
self.assertEqual(distance("G", "T"), 1)
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")
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".+")
if __name__ == "__main__":
unittest.main()