def testAddEmptyValueToList(self): final_letters = [] letters = [] vowel = Vowel(letters) vowel.addToList(final_letters) self.assertEqual(True, len(final_letters) == 0)
def testGetVowelFromLetters(self): letters = [ 'u', 'c', 'y', 'o', 'l', 'j', 'i', 'b', 'r', 'e', 'z', 'a', 'f' ] vowel = Vowel(letters) letter = vowel.getValue() self.assertEqual(True, letter in vowel.getVowels())
def testAddVowelInFirstPositionWhenLastElementIsVowel(self): final_letters = ["c", "o", "r", "e"] letters = ["i"] vowel = Vowel(letters) vowel.addToList(final_letters) self.assertEqual(''.join(["i", "c", "o", "r", "e"]), ''.join(final_letters))
def testAddToList(self): final_letters = [] letters = ['a', 'b', 'c', 'd', 'e', 'f'] vowel = Vowel(letters) vowel.addToList(final_letters) self.assertEqual( True, len(final_letters) > 0 and final_letters[0] in Vowel.getVowels())
def __getVowelIndexNeverUsed(self, diagram_letters): vowels_in_diagram_letters = [i for i in diagram_letters if i in Vowel.getVowels()] for vowel in vowels_in_diagram_letters: vowel_index = diagram_letters.index(vowel) if self.__valueOfIndexAfterVowelIsVowel(diagram_letters, vowel_index, 1) or self.__valueOfIndexAfterVowelIsVowel(diagram_letters, vowel_index, 2): return vowel_index+1 return len(diagram_letters)
def _setProperties(self, phrase_letters): self.exists_vowel_yet = len([i for i in phrase_letters if i in Vowel.getVowels()]) > 0
def __valueOfIndexAfterVowelIsVowel(self, diagram_letters, vowel_index, next_index): if diagram_letters[vowel_index+next_index : vowel_index+next_index+1] == []: return True return len([i for i in diagram_letters[vowel_index+next_index : vowel_index+next_index+1] if i in Vowel.getVowels()]) > 0
from string import ascii_lowercase from Phonemes.AbstractPhoneme import AbstractPhoneme from Phonemes.Vowel import Vowel from Phonemes.Suffix import Suffix consonants = list(filter(lambda x : x not in Vowel.getVowels() + Suffix.getSuffixes(), ascii_lowercase)) class Consonant(AbstractPhoneme): def _setProperties(self, phrase_letters): self.exists_vowel_yet = len([i for i in phrase_letters if i in Vowel.getVowels()]) > 0 def _add(self, diagram_letters): if self.exists_vowel_yet: diagram_letters.append(self.value) else: diagram_letters.insert(self.__getVowelIndexNeverUsed(diagram_letters), self.value) def __getVowelIndexNeverUsed(self, diagram_letters): vowels_in_diagram_letters = [i for i in diagram_letters if i in Vowel.getVowels()] for vowel in vowels_in_diagram_letters: vowel_index = diagram_letters.index(vowel) if self.__valueOfIndexAfterVowelIsVowel(diagram_letters, vowel_index, 1) or self.__valueOfIndexAfterVowelIsVowel(diagram_letters, vowel_index, 2): return vowel_index+1 return len(diagram_letters) def __valueOfIndexAfterVowelIsVowel(self, diagram_letters, vowel_index, next_index): if diagram_letters[vowel_index+next_index : vowel_index+next_index+1] == []: return True return len([i for i in diagram_letters[vowel_index+next_index : vowel_index+next_index+1] if i in Vowel.getVowels()]) > 0