/**
* Sample code with JUnit 4 for the parameterized test
*
*/
package Lab2_Testing.task1;
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(-1, 0, 0, 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
@Test(expected = ComponentOutOfRangeException.class)
public void testException2() throws ComponentOutOfRangeException {
// 6,9
this.calculator.calculateMark(0, 0, 11, 0, true);
}
@Test(expected = ComponentOutOfRangeException.class)
public void testException4() throws ComponentOutOfRangeException {
// 9
this.calculator.calculateMark(0, -1, 0, 0, true);
}
@Test
public void testGradeN2() throws ComponentOutOfRangeException {
//0,5,7
assertEquals(new MarkGrade(59, Grade.P), this.calculator.calculateMark(0, 0, 1, 95, true));
}
@Test
public void testGradeN3() throws ComponentOutOfRangeException {
//2
assertEquals(new MarkGrade(45, Grade.PX), this.calculator.calculateMark(0, 0, 0, 75, true));
}
@Test
public void testGradeN4() throws ComponentOutOfRangeException {
//2,3,5,7
assertEquals(new MarkGrade(80, Grade.HD), this.calculator.calculateMark(0, 3, 10, 100, true));
}
@Test
public void testGradeN5() throws ComponentOutOfRangeException {
//2,4
assertEquals(new MarkGrade(50, Grade.P), this.calculator.calculateMark(2, 7, 8, 43, true));
}
@Test
public void testGradeN6() throws ComponentOutOfRangeException {
// 1
assertEquals(new MarkGrade(null, Grade.NCN), this.calculator.calculateMark(0, 0, 1, 1, false));
}
@Test
public void test2() throws ComponentOutOfRangeException {
// 0,2,3,4,5,7
int mark;
for(int a=0;a<=10;a++) {
for (int b = 0; b <=10; b++) {
for (int c = 0; c <=10; c++) {
for (int d = 0; d <=100; d++) {
mark = (int) Math.round(a * 1.0 + b * 1.5 + c * 1.5 + d * 0.6);
if (mark <= 44 && mark >= 0) {
assertEquals(“error with ” + “a:” + a + “,b:” + b + “,c:” + c + “,d:” + d, new MarkGrade(mark, Grade.N), this.calculator.calculateMark(a, b, c, d, true));
} else if (mark <= 49 && mark >= 45) {
assertEquals(“error with ” + “a:” + a + “,b:” + b + “,c:” + c + “,d:” + d, new MarkGrade(mark, Grade.PX), this.calculator.calculateMark(a, b, c, d, true));
} else if (mark <= 59 && mark >= 50) {
assertEquals(“error with ” + “a:” + a + “,b:” + b + “,c:” + c + “,d:” + d, new MarkGrade(mark, Grade.P), this.calculator.calculateMark(a, b, c, d, true));
} else if (mark <= 69 && mark >= 60) {
assertEquals(“error with ” + “a:” + a + “,b:” + b + “,c:” + c + “,d:” + d, new MarkGrade(mark, Grade.C), this.calculator.calculateMark(a, b, c, d, true));
} else if (mark <= 79 && mark >= 70) {
assertEquals(“error with ” + “a:” + a + “,b:” + b + “,c:” + c + “,d:” + d, new MarkGrade(mark, Grade.D), this.calculator.calculateMark(a, b, c, d, true));
} else if (mark <= 100 && mark >= 80)
assertEquals(“error with ” + “a:” + a + “,b:” + b + “,c:” + c + “,d:” + d, new MarkGrade(mark, Grade.HD), this.calculator.calculateMark(a, b, c, d, true));
}
}
}
}
}
// ########## YOUR CODE ENDS HERE ##########
}