Advertisement
geosabev

python_hw02_tests

Nov 2nd, 2022 (edited)
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.67 KB | None | 0 0
  1. import unittest
  2.  
  3. from solution import (nums_to_text, text_to_nums, nums_to_angle,
  4.                       angles_to_nums, is_phone_tastic)
  5.  
  6.  
  7. class TestNumsToText(unittest.TestCase):
  8.     """Test the nums_to_text function."""
  9.  
  10.     def test_simple_conversion(self):
  11.         """Sanity test for a single number."""
  12.         self.assertEqual(nums_to_text([2]).lower(), 'a')
  13.  
  14.     def test_2(self):
  15.         """Test given example."""
  16.         self.assertEqual(nums_to_text(
  17.             [7, 9, 9, 9, 8, 4, 4, 6, 6, 6, -1, 6, 6]), 'PYTHON')
  18.  
  19.     def test_3(self):
  20.         """Тest second given example."""
  21.         self.assertEqual(nums_to_text(
  22.             [4, 4, 3, 3, 5, 5, 5, -1, 5, 5, 5, 6, 6, 6]), 'HELLO')
  23.  
  24.     def test_4(self):
  25.         """Test over-repeating digit."""
  26.         self.assertEqual(nums_to_text([2, 2, 2, 2, 2, 2, 2, 2]), 'B')
  27.  
  28.     def test_5(self):
  29.         """Test space."""
  30.         self.assertEqual(nums_to_text([2, 2, 0, 1, 3, 3]), 'B E')
  31.  
  32.     def test_6(self):
  33.         """Test single 1."""
  34.         self.assertEqual(nums_to_text([1]), '')
  35.  
  36.     def test_7(self):
  37.         """Test skipping 1."""
  38.         self.assertEqual(nums_to_text([2, 2, 1, 2]), 'BA')
  39.  
  40.     def test_8(self):
  41.         """Test invalid input."""
  42.         self.assertEqual(nums_to_text(
  43.             [2, -10, 2, 2, -10, 2, 2, 2, 10, 3, 'D']), 'ABCD')
  44.  
  45.     def test_9(self):
  46.         """Test empty input."""
  47.         self.assertEqual(nums_to_text([]), '')
  48.  
  49.     def test_10(self):
  50.         """Test multiple consecutive zeros."""
  51.         self.assertTrue(nums_to_text([0, 0, 0, 0, 0]) in [' ', '     '])
  52.  
  53.     def test_11(self):
  54.         """Test from forum."""
  55.         self.assertEqual(nums_to_text([2, 2, 1, 2]), 'BA')
  56.  
  57.  
  58. class TestTextToNums(unittest.TestCase):
  59.     """Test the text_to_nums function."""
  60.  
  61.     def test_simple_conversion(self):
  62.         """Sanity test for a single letter."""
  63.         self.assertEqual(text_to_nums('a'), [2])
  64.  
  65.     def test_2(self):
  66.         """Test given example."""
  67.         self.assertEqual(text_to_nums("asl pls"), [
  68.                          2, 7, 7, 7, 7, 5, 5, 5, 0,
  69.                          7, 5, 5, 5, 7, 7, 7, 7])
  70.  
  71.     def test_3(self):
  72.         """Test given example for nums_to_text."""
  73.         self.assertEqual(text_to_nums("PYTHON"), [
  74.                          7, 9, 9, 9, 8, 4, 4, 6, 6, 6, -1, 6, 6])
  75.  
  76.     def test_4(self):
  77.         """Test repeating letters."""
  78.         self.assertEqual(text_to_nums("aaa bbb ccc"),
  79.                          [2, -1, 2, -1, 2, 0, 2, 2, -1, 2, 2, -1, 2,
  80.                          2, 0, 2, 2, 2, -1, 2, 2, 2, -1, 2, 2, 2])
  81.  
  82.     def test_5(self):
  83.         """Test combined case."""
  84.         self.assertEqual(text_to_nums("aBcDe"),
  85.                          [2, -1, 2, 2, -1, 2, 2, 2, 3, -1, 3, 3])
  86.  
  87.     def test_6(self):
  88.         """Test multiple spaces."""
  89.         self.assertTrue(text_to_nums('a   b   c') in
  90.                         [[2, 0, 0, 0, 2, 2, 0, 0, 0, 2, 2, 2],
  91.                         [2, 0, -1, 0, -1, 0, 2, 2, 0, -1, 0, -1, 0, 2, 2, 2]])
  92.  
  93.     def test_7(self):
  94.         """Test invalid input."""
  95.         self.assertEqual(text_to_nums('A@D#'), [2, 3])
  96.  
  97.     def test_8(self):
  98.         """Test empty input."""
  99.         self.assertEqual(text_to_nums(''), [])
  100.  
  101.     def test_9(self):
  102.         """Test from forum 1."""
  103.         self.assertEqual(text_to_nums('aa'), [2, -1, 2])
  104.  
  105.     def test_10(self):
  106.         """Test from forum 2."""
  107.         self.assertEqual(text_to_nums('baba'), [2, 2, -1, 2, -1, 2, 2, -1, 2])
  108.  
  109.     def test_11(self):
  110.         """Test from forum 3."""
  111.         self.assertEqual(text_to_nums("LLL"), [
  112.                          5, 5, 5, -1, 5, 5, 5, -1, 5, 5, 5])
  113.  
  114.  
  115. class TestNumsToAngles(unittest.TestCase):
  116.     """Test the nums_to_angle function."""
  117.  
  118.     def test_simple_conversion(self):
  119.         """Sanity test for a single number."""
  120.         self.assertEqual(nums_to_angle([1]), 30)
  121.  
  122.     def test_2(self):
  123.         """Test given example."""
  124.         self.assertEqual(nums_to_angle([1, 5, 9]), 90)
  125.  
  126.     def test_3(self):
  127.         """Test under 360 degrees."""
  128.         self.assertEqual(nums_to_angle([1, 9]), 300)
  129.  
  130.     def test_4(self):
  131.         """Test exactly 360 degrees."""
  132.         self.assertEqual(nums_to_angle([1, 2, 9]), 0)
  133.  
  134.     def test_5(self):
  135.         """Test invalid input."""
  136.         self.assertEqual(nums_to_angle(['a', 10]), 0)
  137.  
  138.     def test_6(self):
  139.         """Test empty input."""
  140.         self.assertEqual(nums_to_angle([]), 0)
  141.  
  142.     def test_7(self):
  143.         """Test 330 degrees."""
  144.         self.assertEqual(nums_to_angle([9, 2]), 330)
  145.  
  146.     def test_8(self):
  147.         """Test from forum 1"""
  148.         self.assertEqual(nums_to_angle([1, 9, 3, 2]), 90)
  149.  
  150.     def test_9(self):
  151.         """Test from forum 2"""
  152.         self.assertEqual(nums_to_angle([6, 6]), 0)
  153.  
  154.  
  155. class TestAnglesToNums(unittest.TestCase):
  156.     """Test the angles_to_nums function."""
  157.  
  158.     def test_simple_conversion(self):
  159.         """Sanity test for a single angle."""
  160.         self.assertEqual(angles_to_nums([30]), [1])
  161.  
  162.     def test_2(self):
  163.         """Test given example."""
  164.         self.assertEqual(angles_to_nums([16, 14, 90, -120]), [1, 3, 8])
  165.  
  166.     def test_3(self):
  167.         """Test skipping 0."""
  168.         self.assertEqual(angles_to_nums([0, 40]), [1])
  169.  
  170.     def test_4(self):
  171.         """Test skipping rounded to 0."""
  172.         self.assertEqual(angles_to_nums([5]), [])
  173.  
  174.     def test_5(self):
  175.         """Test skipping 330 degrees."""
  176.         self.assertEqual(angles_to_nums([0, 330]), [])
  177.  
  178.     def test_6(self):
  179.         """Test skipping rounded to 330 degrees."""
  180.         self.assertEqual(angles_to_nums([335, 60]), [2])
  181.  
  182.     def test_7(self):
  183.         """Test over 345 and under 360 degrees."""
  184.         self.assertEqual(angles_to_nums([352]), [])
  185.  
  186.     def test_8(self):
  187.         """Test over 359 degrees."""
  188.         self.assertEqual(angles_to_nums([391]), [1])
  189.  
  190.     def test_9(self):
  191.         """Test from forum 1"""
  192.         self.assertEqual(angles_to_nums(
  193.             [10, 389, -20, 150, 200, 0]), [1, 5, 7])
  194.  
  195.  
  196. class TestIsPhonetastic(unittest.TestCase):
  197.     """Test the is_phone_tastic function."""
  198.  
  199.     def test_simple_word(self):
  200.         """Sanity test for a single letter word."""
  201.         self.assertTrue(is_phone_tastic('a'))
  202.  
  203.     def test_2(self):
  204.         """Test given example."""
  205.         self.assertTrue(is_phone_tastic('GOD'))
  206.  
  207.     def test_3(self):
  208.         """Test including -1."""
  209.         self.assertTrue(is_phone_tastic('AAA'))
  210.  
  211.     def test_4(self):
  212.         """Test empty input."""
  213.         self.assertFalse(is_phone_tastic(''))
  214.  
  215.     def test_5(self):
  216.         """Test from forum 1."""
  217.         self.assertTrue(is_phone_tastic('LLL'))
  218.  
  219.  
  220. if __name__ == '__main__':
  221.     unittest.main()
  222.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement