Checkpint - algorythm works
This commit is contained in:
@ -9,6 +9,7 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
@ -71,13 +72,6 @@ public class AssignmentServiceTest {
|
||||
@DirtiesContext(methodMode = MethodMode.BEFORE_METHOD)
|
||||
public void shouldPerformAcceptAlgorythm() {
|
||||
final Random generator = new Random();
|
||||
final User user1 = this.userService.save(new User(null, null,
|
||||
"shouldPerformAcceptAlgorythm-" + UUID.randomUUID().toString() + "@AssignmentService.test", null,
|
||||
UserRoles.STUDENT, generator.nextInt(400) + 100));
|
||||
|
||||
final User user2 = this.userService.save(new User(null, null,
|
||||
"shouldPerformAcceptAlgorythm-" + UUID.randomUUID().toString() + "@AssignmentService.test", null,
|
||||
UserRoles.STUDENT, generator.nextInt(400) + 100));
|
||||
|
||||
IntStream.range(0, 1700).forEach(i -> {
|
||||
this.userService.save(new User(null, null,
|
||||
@ -90,22 +84,45 @@ public class AssignmentServiceTest {
|
||||
generator.nextInt(9) * 30 + 9 * 30, WeekDay.getDay(generator.nextInt(5)), null));
|
||||
});
|
||||
|
||||
IntStream.range(0, 12).forEach(i -> {
|
||||
user1.claimGroup(this.groupService.save(new Groups(generator.nextInt(80) + 20, null, null,
|
||||
generator.nextInt(9) * 30 + 9 * 30, WeekDay.getDay(generator.nextInt(5)), null)));
|
||||
});
|
||||
this.userService.save(user1);
|
||||
|
||||
IntStream.range(0, 12).forEach(i -> {
|
||||
user2.claimGroup(this.groupService.save(new Groups(generator.nextInt(80) + 20, null, null,
|
||||
generator.nextInt(9) * 30 + 9 * 30, WeekDay.getDay(generator.nextInt(5)), null)));
|
||||
});
|
||||
this.userService.save(user2);
|
||||
|
||||
this.service.callAcceptAlgorythm();
|
||||
System.out.println("-X_-x-x-x-_X-x-x-x-X_-x-x-x-");
|
||||
}
|
||||
|
||||
@Test
|
||||
@DirtiesContext(methodMode = MethodMode.BEFORE_METHOD)
|
||||
public void shouldNotAcceptForOnePerson() {
|
||||
final Random generator = new Random();
|
||||
final Groups group = this.groupService.save(new Groups(5, null, null, 840, WeekDay.MONDAY, null));
|
||||
|
||||
IntStream.range(0, 6).forEach(i -> {
|
||||
final User user = this.userService.save(new User(null, null,
|
||||
"shouldNotAcceptForOnePerson-" + UUID.randomUUID().toString() + "@AssignmentService.test", null,
|
||||
UserRoles.STUDENT, generator.nextInt(400) + 100));
|
||||
|
||||
final Commision com = this.comServie.save(new Commision(user));
|
||||
|
||||
this.service.save(new Assignment(group, com));
|
||||
});
|
||||
|
||||
this.service.callAcceptAlgorythm();
|
||||
|
||||
final List<User> users = this.userService.getStudentsSortedByRanking();
|
||||
final User loser = users.get(users.size() - 1);
|
||||
|
||||
assertTrue(loser.getStudentRegisteredGrups().size() == 0);
|
||||
|
||||
users.forEach(u -> {
|
||||
final Commision com = this.comServie.getNewestCommision(u).get();
|
||||
final List<Assignment> assignments = com.getAssignments();
|
||||
if (u.getId() == loser.getId()) {
|
||||
assertTrue(!assignments.get(0).isAccepted());
|
||||
} else {
|
||||
assertTrue(assignments.get(0).isAccepted());
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void addAssignmentToCommision(Commision com) {
|
||||
Assignment a = new Assignment(null, com);
|
||||
this.service.save(a);
|
||||
|
Reference in New Issue
Block a user