-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
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
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); | ||
} | ||
} |
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
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")); | ||
} | ||
} |