forked from MIT-Emerging-Talent/ET6-practice-code-review
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_reverse_string.py
65 lines (50 loc) · 2.11 KB
/
test_reverse_string.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Unit tests for the reverse_string function.
This module contains several test cases to verify the functionality of the reverse_string function.
It checks the expected behavior for a variety of inputs including:
- A normal string.
- An empty string.
- A string with special characters.
- A string with spaces.
"""
import unittest
from ..reverse_string import reverse_string
class TestReverseString(unittest.TestCase):
"""
Test cases for the reverse_string function.
"""
def test_regular_string(self):
"""Test reversing a regular string."""
self.assertEqual(reverse_string("hello"), "olleh")
def test_empty_string(self):
"""Test reversing an empty string."""
self.assertEqual(reverse_string(""), "")
def test_palindrome(self):
"""Test reversing a palindrome (same forward and backward)."""
self.assertEqual(reverse_string("madam"), "madam")
def test_numbers_in_string(self):
"""Test reversing a string containing numbers."""
self.assertEqual(reverse_string("12345"), "54321")
def test_special_characters(self):
"""Test reversing a string with special characters."""
self.assertEqual(reverse_string("!@#$"), "$#@!")
def test_long_string(self):
"""Test reversing an extremely long string."""
long_string = "a" * 10000
self.assertEqual(reverse_string(long_string), long_string[::-1])
def test_integer_input(self):
"""Test that an integer input raises an AssertionError."""
with self.assertRaises(AssertionError):
reverse_string(12345) # Non-string input: integer
def test_none_input(self):
"""Test that a None input raises an AssertionError."""
with self.assertRaises(AssertionError):
reverse_string(None) # Non-string input: NoneType
def test_list_input(self):
"""Test that a list input raises an AssertionError."""
with self.assertRaises(AssertionError):
reverse_string(["a", "b", "c"]) # Non-string input: list
if __name__ == "__main__":
unittest.main()