/**
* Sample code with JUnit 4 for the parameterized test
*
*/
import static org.junit.Assert.*;
import java.util.Arrays;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;
@RunWith(Parameterized.class)
public class MarkCalculatorTest {
/**
* Return a list of parameters which are different implementation of
* interface {@linkplain MarkCalculator}.
* Do NOT Modify this part
*/
@Parameters
public static Iterable extends Object> getImplementations() {
return Arrays.asList(
new MarkCalculator0(),
new MarkCalculator1(),
new MarkCalculator2(),
new MarkCalculator3(),
new MarkCalculator4(),
new MarkCalculator5(),
new MarkCalculator6(),
new MarkCalculator7(),
new MarkCalculator8(),
new MarkCalculator9()
);
}
@Parameter
public MarkCalculator calculator;
// ########## YOUR CODE STARTS HERE ##########
/* EXAMPLE Test case 1 */
@Test(expected = ComponentOutOfRangeException.class)
public void testException() throws ComponentOutOfRangeException {
this.calculator.calculateMark(0, 0, 12, 0, true);
}
/* EXAMPLE Test case 2 */
@Test
public void testGradeN() throws ComponentOutOfRangeException {
assertEquals(new MarkGrade(0, Grade.N), this.calculator.calculateMark(0, 0, 0, 0, true));
}
//TODO: write other test cases
// ########## YOUR CODE ENDS HERE ##########
@Test
public void testGradedPX() throws ComponentOutOfRangeException{
assertEquals(new MarkGrade(45, Grade.PX), this.calculator.calculateMark(0, 5, 5, 50, true));
}
@Test
public void testNUll() throws ComponentOutOfRangeException{
assertEquals(new MarkGrade(null, Grade.NCN), this.calculator.calculateMark(0, 5, 5, 0, false));
}
@Test
public void testGradedP() throws ComponentOutOfRangeException {
assertEquals(new MarkGrade(50, Grade.P), this.calculator.calculateMark(5, 5, 5, 50, true));
}
@Test
public void testGradedCC() throws ComponentOutOfRangeException {
assertEquals(new MarkGrade(60, Grade.C), this.calculator.calculateMark(7, 10, 5, 50, true));
}
@Test
public void testGradedD() throws ComponentOutOfRangeException {
assertEquals(new MarkGrade(70, Grade.D), this.calculator.calculateMark(8, 0, 1, 100, true));
}
@Test
public void testGradedHD() throws ComponentOutOfRangeException {
assertEquals(new MarkGrade(100, Grade.HD), this.calculator.calculateMark(10, 10, 10, 100, true));
}
@Test
public void testGradedspecialcase() throws ComponentOutOfRangeException {
assertEquals(new MarkGrade(50, Grade.P), this.calculator.calculateMark(2, 7, 8, 43, true));
}
@Test
public void testGradedfloat() throws ComponentOutOfRangeException {
assertEquals(new MarkGrade(59, Grade.P), this.calculator.calculateMark(0, 0, 1, 95, true));
}
}