Commit f6909ae6 authored by a.guest's avatar a.guest

Initial Commit

parents
Pipeline #151 failed with stages
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>UnitTesting</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8
public class FizzBuzz {
private static final int THREE = 3;
private static final int FIVE = 5;
public String calcFizzBuzz(int number)
{
if (isDivisibleBy(number, THREE) &&
isDivisibleBy(number, FIVE)) {
return "FizzBuzz";
}
if (isDivisibleBy(number, THREE)) {
return "Fizz";
}
if (isDivisibleBy(number, FIVE)) {
return "Buzz";
}
return String.valueOf(number);
}
private boolean isDivisibleBy(int dividend, int divisor) {
// (dividend % divisor == 0) is true if dividend divides
// equally by divisor with no remainder and false if not
return (dividend % divisor == 0);
}
}
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
class FizzBuzzTest {
public static int testCount = 0;
public static FizzBuzz test;
@BeforeAll
static void setUpBeforeClass() throws Exception {
test = new FizzBuzz();
}
@BeforeEach
void setUp() throws Exception {
System.out.print("Test #" + testCount + " : ");
testCount++;
}
@AfterEach // Gets called after each test
void tearDown() throws Exception {
System.out.println();
}
// FizzBuzz test
@DisplayName("Fizzbuzz Test")
@ParameterizedTest(name = "#{0} should be {1}")
@CsvSource({
"1,1"
})
void testFizzBuzz(int num, String expected)
{
System.out.print("Number " + num + ", Expected Result " +
expected + ", Actual Result " +
test.calcFizzBuzz(num));
assertEquals(expected, test.calcFizzBuzz(num));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment