Skip to content

Commit

Permalink
fizzbuzz
Browse files Browse the repository at this point in the history
  • Loading branch information
Isaaclot committed May 4, 2021
1 parent ef5f6cb commit 9ba7aac
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/main/java/fizzbuzz/FzBase.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package fizzbuzz;

/**
* @author [email protected]
* @version 1.0
* @since 2021/5/4
*/
public class FzBase {

public static final String FIZZ = "fizz";
public static final String BUZZ = "buzz";

public String say(int num) {
if (num % 3 == 0 && num % 5 == 0) {
return FIZZ + BUZZ;
} else if (num % 3 == 0) {
return FIZZ;
} else if (num % 5 == 0) {
return BUZZ;
}
return String.valueOf(num);
}
}
49 changes: 49 additions & 0 deletions src/test/java/fizzbuzz/FzBaseTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package fizzbuzz;

import org.junit.Test;

import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;

/**
* @author [email protected]
* @version 1.0
* @since 2021/5/4
*/
public class FzBaseTest {
@Test
public void test_given_3_then_fizz() {
FzBase fz = new FzBase();
assertThat(fz.say(3), is("fizz"));
}

@Test
public void test_given_5_then_buzz() {
FzBase fz = new FzBase();
assertThat(fz.say(5), is("buzz"));
}

@Test
public void test_given_6_then_fizz() {
FzBase fz = new FzBase();
assertThat(fz.say(6), is("fizz"));
}

@Test
public void test_given_10_then_buzz() {
FzBase fz = new FzBase();
assertThat(fz.say(10), is("buzz"));
}

@Test
public void test_given_15_then_fizzbuzz() {
FzBase fz = new FzBase();
assertThat(fz.say(15), is("fizzbuzz"));
}

@Test
public void test_given_1_then_1() {
FzBase fz = new FzBase();
assertThat(fz.say(1), is("1"));
}
}

0 comments on commit 9ba7aac

Please sign in to comment.