2023-07-15 15:27:31 -07:00
|
|
|
# These tests are auto-generated with test data from:
|
|
|
|
|
# https://github.com/exercism/problem-specifications/tree/main/exercises/hamming/canonical-data.json
|
2023-07-21 16:54:40 -07:00
|
|
|
# File last updated on 2023-07-19
|
2023-07-15 15:27:31 -07:00
|
|
|
|
2014-04-07 22:32:31 -03:00
|
|
|
import unittest
|
|
|
|
|
|
2021-01-31 16:49:12 -05:00
|
|
|
from hamming import (
|
|
|
|
|
distance,
|
|
|
|
|
)
|
2014-06-11 15:06:22 +02:00
|
|
|
|
2014-04-07 22:32:31 -03:00
|
|
|
|
2019-07-29 23:42:12 -05:00
|
|
|
class HammingTest(unittest.TestCase):
|
2017-10-26 21:08:57 +05:30
|
|
|
def test_empty_strands(self):
|
2019-08-07 09:45:02 -04:00
|
|
|
self.assertEqual(distance("", ""), 0)
|
2017-10-26 21:08:57 +05:30
|
|
|
|
2019-01-08 20:03:03 +05:30
|
|
|
def test_single_letter_identical_strands(self):
|
2019-08-07 09:45:02 -04:00
|
|
|
self.assertEqual(distance("A", "A"), 0)
|
2014-04-07 22:32:31 -03:00
|
|
|
|
2019-01-08 20:03:03 +05:30
|
|
|
def test_single_letter_different_strands(self):
|
2019-08-07 09:45:02 -04:00
|
|
|
self.assertEqual(distance("G", "T"), 1)
|
2014-04-07 22:32:31 -03:00
|
|
|
|
2019-01-08 20:03:03 +05:30
|
|
|
def test_long_identical_strands(self):
|
2019-08-07 09:45:02 -04:00
|
|
|
self.assertEqual(distance("GGACTGAAATCTG", "GGACTGAAATCTG"), 0)
|
2016-11-24 14:42:42 +01:00
|
|
|
|
2019-01-08 20:03:03 +05:30
|
|
|
def test_long_different_strands(self):
|
2019-08-07 09:45:02 -04:00
|
|
|
self.assertEqual(distance("GGACGGATTCTG", "AGGACGGATTCT"), 9)
|
2016-11-24 14:42:42 +01:00
|
|
|
|
|
|
|
|
def test_disallow_first_strand_longer(self):
|
2021-10-25 14:05:13 -07:00
|
|
|
with self.assertRaises(ValueError) as err:
|
2019-08-07 09:45:02 -04:00
|
|
|
distance("AATG", "AAA")
|
2016-11-24 14:42:42 +01:00
|
|
|
|
2021-10-25 14:05:13 -07:00
|
|
|
self.assertEqual(type(err.exception), ValueError)
|
|
|
|
|
self.assertEqual(err.exception.args[0], "Strands must be of equal length.")
|
|
|
|
|
|
2021-11-10 12:55:43 -08:00
|
|
|
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.")
|