Skip to content

Instantly share code, notes, and snippets.

@rodrigomanhaes
Created October 27, 2011 18:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rodrigomanhaes/1320484 to your computer and use it in GitHub Desktop.
Save rodrigomanhaes/1320484 to your computer and use it in GitHub Desktop.
Testes em Java "modo procedural"
/* 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);
}
}
@gabriellima
Copy link

In line 31-33, could it change to:

return (numero == 0) ? 1 : numero * fatorial(numero - 1);

?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment