Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import unittest
- from solution import (nums_to_text, text_to_nums, nums_to_angle,
- angles_to_nums, is_phone_tastic)
- class TestNumsToText(unittest.TestCase):
- """Test the nums_to_text function."""
- def test_simple_conversion(self):
- """Sanity test for a single number."""
- self.assertEqual(nums_to_text([2]).lower(), 'a')
- def test_2(self):
- """Test given example."""
- self.assertEqual(nums_to_text(
- [7, 9, 9, 9, 8, 4, 4, 6, 6, 6, -1, 6, 6]), 'PYTHON')
- def test_3(self):
- """Тest second given example."""
- self.assertEqual(nums_to_text(
- [4, 4, 3, 3, 5, 5, 5, -1, 5, 5, 5, 6, 6, 6]), 'HELLO')
- def test_4(self):
- """Test over-repeating digit."""
- self.assertEqual(nums_to_text([2, 2, 2, 2, 2, 2, 2, 2]), 'B')
- def test_5(self):
- """Test space."""
- self.assertEqual(nums_to_text([2, 2, 0, 1, 3, 3]), 'B E')
- def test_6(self):
- """Test single 1."""
- self.assertEqual(nums_to_text([1]), '')
- def test_7(self):
- """Test skipping 1."""
- self.assertEqual(nums_to_text([2, 2, 1, 2]), 'BA')
- def test_8(self):
- """Test invalid input."""
- self.assertEqual(nums_to_text(
- [2, -10, 2, 2, -10, 2, 2, 2, 10, 3, 'D']), 'ABCD')
- def test_9(self):
- """Test empty input."""
- self.assertEqual(nums_to_text([]), '')
- def test_10(self):
- """Test multiple consecutive zeros."""
- self.assertTrue(nums_to_text([0, 0, 0, 0, 0]) in [' ', ' '])
- def test_11(self):
- """Test from forum."""
- self.assertEqual(nums_to_text([2, 2, 1, 2]), 'BA')
- class TestTextToNums(unittest.TestCase):
- """Test the text_to_nums function."""
- def test_simple_conversion(self):
- """Sanity test for a single letter."""
- self.assertEqual(text_to_nums('a'), [2])
- def test_2(self):
- """Test given example."""
- self.assertEqual(text_to_nums("asl pls"), [
- 2, 7, 7, 7, 7, 5, 5, 5, 0,
- 7, 5, 5, 5, 7, 7, 7, 7])
- def test_3(self):
- """Test given example for nums_to_text."""
- self.assertEqual(text_to_nums("PYTHON"), [
- 7, 9, 9, 9, 8, 4, 4, 6, 6, 6, -1, 6, 6])
- def test_4(self):
- """Test repeating letters."""
- self.assertEqual(text_to_nums("aaa bbb ccc"),
- [2, -1, 2, -1, 2, 0, 2, 2, -1, 2, 2, -1, 2,
- 2, 0, 2, 2, 2, -1, 2, 2, 2, -1, 2, 2, 2])
- def test_5(self):
- """Test combined case."""
- self.assertEqual(text_to_nums("aBcDe"),
- [2, -1, 2, 2, -1, 2, 2, 2, 3, -1, 3, 3])
- def test_6(self):
- """Test multiple spaces."""
- self.assertTrue(text_to_nums('a b c') in
- [[2, 0, 0, 0, 2, 2, 0, 0, 0, 2, 2, 2],
- [2, 0, -1, 0, -1, 0, 2, 2, 0, -1, 0, -1, 0, 2, 2, 2]])
- def test_7(self):
- """Test invalid input."""
- self.assertEqual(text_to_nums('A@D#'), [2, 3])
- def test_8(self):
- """Test empty input."""
- self.assertEqual(text_to_nums(''), [])
- def test_9(self):
- """Test from forum 1."""
- self.assertEqual(text_to_nums('aa'), [2, -1, 2])
- def test_10(self):
- """Test from forum 2."""
- self.assertEqual(text_to_nums('baba'), [2, 2, -1, 2, -1, 2, 2, -1, 2])
- def test_11(self):
- """Test from forum 3."""
- self.assertEqual(text_to_nums("LLL"), [
- 5, 5, 5, -1, 5, 5, 5, -1, 5, 5, 5])
- class TestNumsToAngles(unittest.TestCase):
- """Test the nums_to_angle function."""
- def test_simple_conversion(self):
- """Sanity test for a single number."""
- self.assertEqual(nums_to_angle([1]), 30)
- def test_2(self):
- """Test given example."""
- self.assertEqual(nums_to_angle([1, 5, 9]), 90)
- def test_3(self):
- """Test under 360 degrees."""
- self.assertEqual(nums_to_angle([1, 9]), 300)
- def test_4(self):
- """Test exactly 360 degrees."""
- self.assertEqual(nums_to_angle([1, 2, 9]), 0)
- def test_5(self):
- """Test invalid input."""
- self.assertEqual(nums_to_angle(['a', 10]), 0)
- def test_6(self):
- """Test empty input."""
- self.assertEqual(nums_to_angle([]), 0)
- def test_7(self):
- """Test 330 degrees."""
- self.assertEqual(nums_to_angle([9, 2]), 330)
- def test_8(self):
- """Test from forum 1"""
- self.assertEqual(nums_to_angle([1, 9, 3, 2]), 90)
- def test_9(self):
- """Test from forum 2"""
- self.assertEqual(nums_to_angle([6, 6]), 0)
- class TestAnglesToNums(unittest.TestCase):
- """Test the angles_to_nums function."""
- def test_simple_conversion(self):
- """Sanity test for a single angle."""
- self.assertEqual(angles_to_nums([30]), [1])
- def test_2(self):
- """Test given example."""
- self.assertEqual(angles_to_nums([16, 14, 90, -120]), [1, 3, 8])
- def test_3(self):
- """Test skipping 0."""
- self.assertEqual(angles_to_nums([0, 40]), [1])
- def test_4(self):
- """Test skipping rounded to 0."""
- self.assertEqual(angles_to_nums([5]), [])
- def test_5(self):
- """Test skipping 330 degrees."""
- self.assertEqual(angles_to_nums([0, 330]), [])
- def test_6(self):
- """Test skipping rounded to 330 degrees."""
- self.assertEqual(angles_to_nums([335, 60]), [2])
- def test_7(self):
- """Test over 345 and under 360 degrees."""
- self.assertEqual(angles_to_nums([352]), [])
- def test_8(self):
- """Test over 359 degrees."""
- self.assertEqual(angles_to_nums([391]), [1])
- def test_9(self):
- """Test from forum 1"""
- self.assertEqual(angles_to_nums(
- [10, 389, -20, 150, 200, 0]), [1, 5, 7])
- class TestIsPhonetastic(unittest.TestCase):
- """Test the is_phone_tastic function."""
- def test_simple_word(self):
- """Sanity test for a single letter word."""
- self.assertTrue(is_phone_tastic('a'))
- def test_2(self):
- """Test given example."""
- self.assertTrue(is_phone_tastic('GOD'))
- def test_3(self):
- """Test including -1."""
- self.assertTrue(is_phone_tastic('AAA'))
- def test_4(self):
- """Test empty input."""
- self.assertFalse(is_phone_tastic(''))
- def test_5(self):
- """Test from forum 1."""
- self.assertTrue(is_phone_tastic('LLL'))
- if __name__ == '__main__':
- unittest.main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement