FizzBuzzTest.java 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import static org.junit.Assert.*;
  2. import org.junit.After;
  3. import org.junit.Before;
  4. import org.junit.Test;
  5. /**
  6. * The test class FizzBuzzTest.
  7. *
  8. * @author (your name)
  9. * @version (a version number or a date)
  10. */
  11. public class FizzBuzzTest
  12. {
  13. /**
  14. * Default constructor for test class FizzBuzzTest
  15. */
  16. public FizzBuzzTest(){
  17. }
  18. @Test
  19. public void FizzForMultiplesOfThreeButNotFive() {
  20. String expected = "Fizz";
  21. for (int i = 1; i<=100; i++ ) {
  22. if ((i%3 == 0) && !(i%5==0)) {
  23. String actual = "Fizz";
  24. assertEquals(expected, actual);
  25. }
  26. }
  27. }
  28. @Test
  29. public void BuzzForMultiplesOfFiveButNotThree() {
  30. String expected = "Buzz";
  31. for (int i = 1; i<=100; i++ ) {
  32. if ((i%5 == 0) && !(i%3==0)) {
  33. String actual = "Buzz";
  34. assertEquals(expected, actual);
  35. }
  36. }
  37. }
  38. @Test
  39. public void FizzBuzzForMultiplesOfThreeAndFive() {
  40. String expected = "FizzBuzz";
  41. for (int i = 1; i<=100; i++ ) {
  42. if ((i%3 == 0) && (i%5==0)) {
  43. String actual = "FizzBuzz";
  44. assertEquals(expected, actual);
  45. }
  46. }
  47. }
  48. }