package geniusweb.bidspace.pareto; import static org.junit.Assert.assertEquals; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Arrays; import java.util.Collection; import java.util.LinkedList; import java.util.List; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; import com.fasterxml.jackson.databind.ObjectMapper; import geniusweb.profile.Profile; import geniusweb.profile.utilityspace.LinearAdditive; import geniusweb.profile.utilityspace.LinearAdditiveUtilitySpace; /** * Test pareto functionality with some real profiles in an e2e test */ @RunWith(Parameterized.class) public class ParetoE2Etest { private final static ObjectMapper jackson = new ObjectMapper(); @Parameters public static Collection data() { return Arrays.asList(new Object[][] { { "src/test/resources/jobs/jobs1.json", "src/test/resources/jobs/jobs2.json", 18 }, { "src/test/resources/7issues/7issues1.json", "src/test/resources/7issues/7issues2.json", 351 } }); } private Path path1; private Path path2; private int expectedNrPoints; public ParetoE2Etest(String profile1file, String profile2file, int expectedNr) { this.path1 = Paths.get(profile1file); this.path2 = Paths.get(profile2file); this.expectedNrPoints = expectedNr; } @Test public void checkGenerciPareto() throws IOException { String file1 = new String(Files.readAllBytes(path1)); LinearAdditiveUtilitySpace profile1 = (LinearAdditiveUtilitySpace) jackson .readValue(file1, Profile.class); String file2 = new String(Files.readAllBytes(path2)); LinearAdditiveUtilitySpace profile2 = (LinearAdditiveUtilitySpace) jackson .readValue(file2, Profile.class); List profiles = new LinkedList<>(); profiles.add(profile1); profiles.add(profile2); ParetoFrontier linaddpareto = new ParetoLinearAdditive(profiles); System.out.println("linaddpareto result" + linaddpareto); assertEquals(expectedNrPoints, linaddpareto.getPoints().size()); if (expectedNrPoints < 40) { ParetoFrontier generalpareto = new GenericPareto(profiles); assertEquals(generalpareto.getPoints(), linaddpareto.getPoints()); System.out.println("generalpareto result" + generalpareto); } else { System.out.println("Skippedn generalpareto - expected too slow"); } } }