Created
May 12, 2012 23:01
-
-
Save Cherubi/2669610 to your computer and use it in GitHub Desktop.
05 NimenToistaminen
This file contains 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
import org.junit.Test; | |
import org.junit.Rule; | |
import static org.junit.Assert.*; | |
import fi.helsinki.cs.tmc.edutestutils.Points; | |
import fi.helsinki.cs.tmc.edutestutils.MockStdio; | |
@Points("1.5") | |
public class NimenToistaminenTest { | |
@Rule | |
public MockStdio io = new MockStdio(); | |
@Test | |
public void uolevi() { | |
io.setSysIn("Uolevi\n"); | |
NimenToistaminen.main(new String[0]); | |
String tulostus = io.getSysOut(); | |
assertTrue("Ohjelma ei tulosta mitään", tulostus.length() > 0); | |
if (tulostus.toLowerCase().startsWith("anna nimi:\n") || tulostus.toLowerCase().startsWith("anna nimi: \n") ) { | |
tulostus = tulostus.substring( tulostus.indexOf("\n") + 1 ); | |
} | |
String[] rivit = tulostus.split("\n"); | |
int maara = rivit.length; | |
assertTrue("Ohjelma tulostaa " + maara + " riviä 3:n sijasta\n" + tulostus, maara == 3); | |
for (int i = 0; i < 3; i++) { | |
assertTrue("Ohjelma tulostaa väärin " + (i + 1) + ". rivin", rivit[i].trim().indexOf("Uolevi") != -1); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment