Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Count the vowels in the sentence. #59

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
COUNT vowel
  • Loading branch information
majdadel20 committed Jan 7, 2025
commit 9ad0835b4d5be4656b0c63252fe18cb919062c95
72 changes: 32 additions & 40 deletions solutions/tests/test_count_vowel
Original file line number Diff line number Diff line change
@@ -1,47 +1,39 @@
import unittest

def count_vowels_recursively(string):

if not string:

return 0
else:
if string[0].lower() in 'aeiou':
return 1 + count_vowels_recursively(string[1:])
else:
return count_vowels_recursively(string[1:])

input_string = "Palestinian culture is beautiful."
a = count_vowels_recursively(input_string)
print(f"Number of vowels in '{input_string}' is: {a}")
# Test cases for the function count_vowels_recursively



def test_count_vowels_recursively():
# Test case 1: Empty string
assert count_vowels_recursively("") == 0, "Test case 1 failed"

# Test case 2: String with no vowels
assert count_vowels_recursively("bcdfghjklmnpqrstvwxyz") == 0, "Test case 2 failed"

# Test case 3: String with only vowels
assert count_vowels_recursively("aeiouAEIOU") == 10, "Test case 3 failed"

# Test case 4: Mixed string
assert count_vowels_recursively("hello world") == 3, "Test case 4 failed"

# Test case 5: Complex sentence
assert count_vowels_recursively("The quick brown fox jumps over the lazy dog") == 11, "Test case 5 failed"

# Test case 6: String with special characters and spaces
assert count_vowels_recursively("!@#$%^&*()_+ 1234567890-=") == 0, "Test case 6 failed"

# Test case 7: Single character (vowel)
assert count_vowels_recursively("a") == 1, "Test case 7 failed"

# Test case 8: Single character (non-vowel)
assert count_vowels_recursively("b") == 0, "Test case 8 failed"

print("All test cases passed!")

# Run the tests
test_count_vowels_recursively()
return count_vowels_recursively(string[1:])

class TestCountVowelsRecursively(unittest.TestCase):

def test_empty_string(self):
self.assertEqual(count_vowels_recursively(""), 0)

def test_no_vowels(self):
self.assertEqual(count_vowels_recursively("bcdfghjklmnpqrstvwxyz"), 0)

def test_only_vowels(self):
self.assertEqual(count_vowels_recursively("aeiouAEIOU"), 10)

def test_mixed_string(self):
self.assertEqual(count_vowels_recursively("hello world"), 3)

def test_complex_sentence(self):
self.assertEqual(count_vowels_recursively("The quick brown fox jumps over the lazy dog"), 11)

def test_special_characters(self):
self.assertEqual(count_vowels_recursively("!@#$%^&*()_+ 1234567890-="), 0)

def test_single_vowel(self):
self.assertEqual(count_vowels_recursively("a"), 1)

def test_single_non_vowel(self):
self.assertEqual(count_vowels_recursively("b"), 0)

if __name__ == '__main__':
unittest.main()
Loading