package comp1110.ass1;
import java.util.HashSet;
import org.junit.jupiter.api.*;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static org.junit.jupiter.api.Assertions.assertTrue;
@Timeout(value = 1000, unit = MILLISECONDS)
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class NewObjectiveTest {
private int getDifficulty(Objective objective) {
for (int i = 0; i < Objective.OBJECTIVES.length; i++) {
if (objective == Objective.OBJECTIVES[i])
return i / (Objective.OBJECTIVES.length/4);
}
return -1;
}
private int countObjectives(Objective[] objectives) {
HashSet
for (Objective o : objectives)
set.add(o);
return set.size();
}
private void doTest(int difficulty) {
Objective[] out = new Objective[12];
for (int i = 0; i < out.length; i++) {
out[i] = Objective.newObjective(difficulty);
int diff = getDifficulty(out[i]);
assertTrue(diff == difficulty, "Expected difficulty " + difficulty + ", but " + (diff == -1 ? "did not get one from the prepared objectives" : "got one of difficulty " + diff) + ": problem number " + out[i].getProblemNumber() + ".");
}
int unique = countObjectives(out);
assertTrue(unique >= 3, “Expected at least 3 different objectives after calling newObjective() 12 times, but only got ” + unique + “.”);
}
@Test
public void testStarter() {
doTest(0);
}
@Test
public void testJunior() {
doTest(1);
}
@Test
public void testExpert() {
doTest(2);
}
@Test
public void testMaster() {
doTest(3);
}
}