Files
python/exercises/practice/hamming/hamming_test.py
BethanyG e7a6b0dc7d [JinJa2] Corrected the macro used for comments on the test file. (#3373)
* Corrected the macro for comments on the test file.
* Added current_date (utcnow()) variable available for template macros.
* Removed unnecessary datetime import from macros file.
* Regenerated all practice exercise test files to add timestamp.
* Changed `datetime.now(tz=timezone.utc)` to `datetime.now(tz=timezone.utc).date()`
* Second regeneration to remove `timestamp` and just keep `date` for test files.
[no important files changed]
2023-07-14 15:52:15 -07:00

55 lines
1.9 KiB
Python

import unittest
from hamming import (
distance,
)
# 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-14
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.")