mirror of
https://github.com/Xevion/exercism.git
synced 2025-12-07 11:15:01 -06:00
'init'
This commit is contained in:
53
python/hamming/hamming_test.py
Normal file
53
python/hamming/hamming_test.py
Normal 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()
|
||||
Reference in New Issue
Block a user