forked from reingart/exercism
-
Notifications
You must be signed in to change notification settings - Fork 4
/
hamming_test.py
54 lines (38 loc) · 1.86 KB
/
hamming_test.py
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
47
48
49
50
51
52
53
54
# These tests are auto-generated with test data from:
# https://github.com/exercism/problem-specifications/tree/main/exercises/hamming/canonical-data.json
# File last updated on 2023-07-19
import unittest
from hamming import (
distance,
)
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.assertRaises(ValueError) as err:
distance("AATG", "AAA")
self.assertEqual(type(err.exception), ValueError)
self.assertEqual(err.exception.args[0], "Strands must be of equal length.")
def test_disallow_second_strand_longer(self):
with self.assertRaises(ValueError) as err:
distance("ATA", "AGTG")
self.assertEqual(type(err.exception), ValueError)
self.assertEqual(err.exception.args[0], "Strands must be of equal length.")
def test_disallow_empty_first_strand(self):
with self.assertRaises(ValueError) as err:
distance("", "G")
self.assertEqual(type(err.exception), ValueError)
self.assertEqual(err.exception.args[0], "Strands must be of equal length.")
def test_disallow_empty_second_strand(self):
with self.assertRaises(ValueError) as err:
distance("G", "")
self.assertEqual(type(err.exception), ValueError)
self.assertEqual(err.exception.args[0], "Strands must be of equal length.")