Last active
April 10, 2018 14:52
-
-
Save loloof64/5d56603f2b6010339160f2ee28510d5d to your computer and use it in GitHub Desktop.
WildCoderTDD
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package fr.wildcodeschool.unittesting; | |
public class StringUtils { | |
private static final String ALL_VOWELS = "aeiouyAEIOUY"; | |
/** | |
* Renvoie la chaine formée par les voyelles d'une chaine de caractères | |
* @return Chaine avec uniquement des voyelles | |
*/ | |
public static String vowels(String candidate) { | |
if (candidate == null) throw new IllegalArgumentException("The candidate string is null."); | |
String vowels = ""; | |
char[] letters = candidate.toCharArray(); | |
for (int i = 0; i < candidate.length(); i++) { | |
if (ALL_VOWELS.indexOf(letters[i]) >= 0 && vowels.indexOf(letters[i]) == -1) { | |
vowels += letters[i]; | |
} | |
} | |
return vowels; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package fr.wildcodeschool.unittesting; | |
import org.junit.Test; | |
import org.junit.jupiter.api.BeforeEach; | |
import static org.junit.jupiter.api.Assertions.assertEquals; | |
public class StringUtilsTest { | |
private StringUtils stringUtilsInstance; | |
@BeforeEach | |
public void setup(){ | |
stringUtilsInstance = new StringUtils(); | |
} | |
@Test | |
public void voyelsTakesTheFirstCharacterIntoAccount(){ | |
String testedString = "ABOEI"; | |
assertEquals("AOEI", StringUtils.vowels(testedString)); | |
} | |
@Test | |
public void voyelsTakesLowercaseLetterYIntoAccount(){ | |
String testedString = "aybcne"; | |
assertEquals("aye", StringUtils.vowels(testedString)); | |
} | |
@Test | |
public void voyelsTakesUppercaseLetterYIntoAccount(){ | |
String testedString = "AYBNCE"; | |
assertEquals("AYE", StringUtils.vowels(testedString)); | |
} | |
@Test | |
public void voyelsWithSeveralInstancesOfSameVoyelReturnsItOnce(){ | |
assertEquals("A", StringUtils.vowels("AAAA")); | |
} | |
@Test | |
public void voyelsWithEmptyStringReturnsEmptyString(){ | |
assertEquals("", StringUtils.vowels("")); | |
} | |
@Test(expected = IllegalArgumentException.class) | |
public void voyelsThrowExceptionIfParameterNotGiven(){ | |
StringUtils.vowels(null); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment