This repository contains a set of Python functions that manipulate strings and lists in various ways. Your task is to implement and thoroughly test each function, including edge cases.
-
Description: Increment the numeric suffix of a string.
- If the string ends with a number, increment that number by 1.
- If the string does not end with a number, append
1.
-
Examples:
"foo" -> "foo1" "foobar23" -> "foobar24" "foo0042" -> "foo0043" "foo9" -> "foo10" "foo099" -> "foo100"
-
Description: Count the occurrences of each letter in a string.
-
Example:
"aba" -> {"a": 2, "b": 1}
-
Description: Return a list of sums of each consecutive pair in a list.
-
Example:
[1, 2, 3] -> [3, 5] # 1+2=3, 2+3=5
-
Description: Count the number of unique words in a string.
-
Should raise a
ValueErrorif the input is not a string. -
Example:
"no example ;)"
-
Implement all functions in the main Python file (e.g.,
main.py). -
Write comprehensive tests for all functions, including edge cases, such as:
- Empty strings
- Strings without numbers
- Lists with a single element
- Non-string inputs for
count_unique
-
Place all test cases in a separate file:
tests/test.py -
Use Python's built-in
unittestframework for testing. Example:import unittest from main import increment_string class TestIncrementString(unittest.TestCase): def test_increment_no_number(self): self.assertEqual(increment_string("foo"), "foo1") def test_increment_with_number(self): self.assertEqual(increment_string("foo009"), "foo010") if __name__ == "__main__": unittest.main()
-
Ensure all tests pass before submission.