Skip to content
Snippets Groups Projects
Commit cf144337 authored by MICHOUD KEVIN's avatar MICHOUD KEVIN
Browse files

updated removing solutions

parent 5216353e
Branches
No related merge requests found
......@@ -100,30 +100,6 @@ def factorial(n):
def count_vowels(s: str) -> int:
"""
Count the number of vowels (a, e, i, o, u, y) in a given string.
Parameters:
- s (str): The string in which vowels are to be counted.
Returns:
- int: The number of vowels in the string.
Doctest:
>>> count_vowels("hello")
2
>>> count_vowels("apple")
2
>>> count_vowels("why")
1
>>> count_vowels("AEIOU")
5
>>> count_vowels("aEiOu")
5
>>> count_vowels("")
0
"""
vowels = "aeiouyAEIOUY"
count = sum(1 for char in s if char in vowels)
return count
......
......@@ -2,44 +2,53 @@
Created by kevin-desktop, on the 28/09/2023
"""
import unittest
from functions import add, fibo, factorial, count_vowels # Replace 'your_module_name' with the name of your module
from functions import add, fibo, factorial, \
count_vowels # Replace 'your_module_name' with the name of your module
class TestFunctions(unittest.TestCase):
# Test cases for add function
def test_add(self):
self.assertEqual(add(3, -2), 1, "Integers addition failed")
self.assertAlmostEqual(add(1/3, 1/2), 0.8333333333333333, places=6, msg="Floats addition failed")
self.assertTrue(isinstance(add("doc", "strings"), str), "Return type is not string")
self.assertNotEqual(add(3, 3), 7, "Integers addition result is not as expected")
self.assertAlmostEqual(add(1 / 3, 1 / 2), 0.8333333333333333, places=6,
msg="Floats addition failed")
self.assertTrue(isinstance(add("doc", "strings"), str),
"Return type is not string")
self.assertNotEqual(add(3, 3), 7,
"Integers addition result is not as expected")
# Test cases for fibo function
def test_fibo(self):
self.assertEqual(fibo(0), 0, "Fibo for 0 failed")
self.assertEqual(fibo(10), 55, "Fibo for 10 failed")
with self.assertRaises(TypeError, msg="String input should raise TypeError"):
with self.assertRaises(TypeError,
msg="String input should raise TypeError"):
fibo("nine")
with self.assertRaisesRegex(TypeError, "type int", msg="Float input should raise a specific TypeError"):
with self.assertRaisesRegex(TypeError, "type int", msg="Float input "
"should raise "
"a specific "
"TypeError"):
fibo(0.2)
with self.assertRaises(ValueError, msg="Negative integer input should raise ValueError"):
with self.assertRaises(ValueError, msg="Negative integer input should "
"raise ValueError"):
fibo(-1)
# Test cases for factorial function
def test_factorial(self):
self.assertIn(factorial(5), [120], "Factorial of 5 failed")
self.assertNotIn(factorial(5), [121, 119], "Factorial of 5 had unexpected results")
with self.assertRaises(ValueError, msg="Negative integer input should raise ValueError"):
self.assertNotIn(factorial(5), [121, 119],
"Factorial of 5 had unexpected results")
with self.assertRaises(ValueError, msg="Negative integer input should "
"raise ValueError"):
factorial(-1)
with self.assertRaises(ValueError, msg="Non-exact integer input should raise ValueError"):
with self.assertRaises(ValueError,
msg="Non-exact integer input should raise "
"ValueError"):
factorial(30.1)
self.assertIsInstance(factorial(30.0), int, "Return type for factorial of 30.0 is not integer")
self.assertIsInstance(factorial(30.0), int,
"Return type for factorial of 30.0 is not integer")
# Test cases for count_vowels function
def test_count_vowels(self):
self.assertGreater(count_vowels("apple"), 1, "Number of vowels in 'apple' should be greater than 1")
self.assertLessEqual(count_vowels("why"), 1, "Number of vowels in 'why' should be 1 or less")
self.assertEqual(count_vowels("AEIOU"), 5, "Uppercase vowels count failed")
self.assertEqual(count_vowels(""), 0, "Empty string should have 0 vowels")
if __name__ == '__main__':
unittest.main()
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment