Skip to content

Instantly share code, notes, and snippets.

@j4rv
Created March 15, 2019 12:02
Show Gist options
  • Save j4rv/2cfa584b1df0d082906d5b782c128a6f to your computer and use it in GitHub Desktop.
Save j4rv/2cfa584b1df0d082906d5b782c128a6f to your computer and use it in GitHub Desktop.
@RunWith(Parameterized.class)
public class CalculatorTest {
enum Type {SUBSTRACT, ADD};
@Parameters
public static Collection<Object[]> data(){
return Arrays.asList(new Object[][] {
{Type.SUBSTRACT, 3.0, 2.0, 1.0},
{Type.ADD, 23.0, 5.0, 28.0}
});
}
private Type type;
private Double a, b, expected;
public CalculatorTest(Type type, Double a, Double b, Double expected){
this.type = type;
this.a=a; this.b=b; this.expected=expected;
}
@Test
public void testAdd(){
Assume.assumeTrue(type == Type.ADD);
assertEquals(expected, Calculator.add(a, b));
}
@Test
public void testSubstract(){
Assume.assumeTrue(type == Type.SUBSTRACT);
assertEquals(expected, Calculator.substract(a, b));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment