Created
October 27, 2011 18:59
-
-
Save rodrigomanhaes/1320484 to your computer and use it in GitHub Desktop.
Testes em Java "modo procedural"
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
/* Exemplos de testes (emulando o modo procedural) em Java */ | |
/* Arquivo: FatorialTest.java */ | |
package exercicio13; | |
import static exercicio13.Fatorial.fatorial; | |
import static org.junit.Assert.*; | |
import org.junit.Test; | |
public class FatorialTest { | |
@Test | |
public void calculaFatorial() { | |
assertEquals(1, fatorial(0)); | |
assertEquals(1, fatorial(1)); | |
assertEquals(2, fatorial(2)); | |
assertEquals(6, fatorial(3)); | |
assertEquals(24, fatorial(4)); | |
assertEquals(120, fatorial(5)); | |
} | |
} | |
/* Arquivo: Fatorial.java */ | |
package exercicio13; | |
public class Fatorial { | |
public static int fatorial(int numero) { | |
if (numero == 0) | |
return 1; | |
return numero * fatorial(numero - 1); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In line 31-33, could it change to:
?