forked from MIT-Emerging-Talent/ET6-practice-code-review
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_palindrome_checker.py
74 lines (59 loc) · 2.33 KB
/
test_palindrome_checker.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
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Test module for palindrome_checker function.
Test categories:
- Standard cases: typical palindromes and non-palindromes
- Edge cases: empty strings, single characters, mixed-case strings
- Defensive tests: wrong input types, assertions
Created on 2/1/2025
@author: Caesar Ghazi
"""
import unittest
from ..palindrome_checker import palindrome_checker
class TestPalindromeChecker(unittest.TestCase):
"""Test if the function correctly identifies palindromes."""
# Standard test cases
def test_simple_palindrome(self):
"""it should return True for a palindrome."""
actual = palindrome_checker("racecar")
expected = True
self.assertEqual(actual, expected)
def test_non_palindrome(self):
"""it should return False for a non-palindrome string."""
actual = palindrome_checker("hello")
expected = False
self.assertEqual(actual, expected)
def test_mixed_case_palindrome(self):
"""it should return True for palindromes for capital letters too."""
actual = palindrome_checker("RaceCar")
expected = True
self.assertEqual(actual, expected)
def test_palindrome_with_punctuation(self):
"""it should return True and ignore spaces and punctuation."""
actual = palindrome_checker("No lemon, no melon")
expected = True
self.assertEqual(actual, expected)
# Edge cases
def test_empty_string(self):
"""it should return True for an empty string."""
actual = palindrome_checker("")
expected = True
self.assertEqual(actual, expected)
def test_single_character(self):
"""it should return True for a single character."""
actual = palindrome_checker("a")
expected = True
self.assertEqual(actual, expected)
def test_palindrome_with_numbers(self):
"""it should handle numeric palindromes correctly."""
actual = palindrome_checker("12321")
expected = True
self.assertEqual(actual, expected)
# Defensive Tests
def test_invalid_text_type(self):
"""it should raise an AssertionError if the text parameter is not a string."""
with self.assertRaises(AssertionError):
palindrome_checker(12345)
if __name__ == "__main__":
unittest.main()