source: bidspace/src/test/java/geniusweb/bidspace/pareto/ParetoE2Etest.java@ 52

Last change on this file since 52 was 52, checked in by ruud, 14 months ago

Fixed small issues in domaineditor.

File size: 2.4 KB
Line 
1package geniusweb.bidspace.pareto;
2
3import static org.junit.Assert.assertEquals;
4
5import java.io.IOException;
6import java.nio.file.Files;
7import java.nio.file.Path;
8import java.nio.file.Paths;
9import java.util.Arrays;
10import java.util.Collection;
11import java.util.LinkedList;
12import java.util.List;
13
14import org.junit.Test;
15import org.junit.runner.RunWith;
16import org.junit.runners.Parameterized;
17import org.junit.runners.Parameterized.Parameters;
18
19import com.fasterxml.jackson.databind.ObjectMapper;
20
21import geniusweb.profile.Profile;
22import geniusweb.profile.utilityspace.LinearAdditive;
23import geniusweb.profile.utilityspace.LinearAdditiveUtilitySpace;
24
25/**
26 * Test pareto functionality with some real profiles in an e2e test
27 */
28@RunWith(Parameterized.class)
29public class ParetoE2Etest {
30 private final static ObjectMapper jackson = new ObjectMapper();
31
32 @Parameters
33 public static Collection<Object[]> data() {
34 return Arrays.asList(new Object[][] {
35 { "src/test/resources/jobs/jobs1.json",
36 "src/test/resources/jobs/jobs2.json", 18 },
37 { "src/test/resources/7issues/7issues1.json",
38 "src/test/resources/7issues/7issues2.json", 557 } });
39 }
40
41 private Path path1;
42 private Path path2;
43 private int expectedNrPoints;
44
45 public ParetoE2Etest(String profile1file, String profile2file,
46 int expectedNr) {
47 this.path1 = Paths.get(profile1file);
48 this.path2 = Paths.get(profile2file);
49 this.expectedNrPoints = expectedNr;
50 }
51
52 @Test
53 public void checkGenerciPareto() throws IOException {
54 String file1 = new String(Files.readAllBytes(path1));
55 LinearAdditiveUtilitySpace profile1 = (LinearAdditiveUtilitySpace) jackson
56 .readValue(file1, Profile.class);
57 String file2 = new String(Files.readAllBytes(path2));
58 LinearAdditiveUtilitySpace profile2 = (LinearAdditiveUtilitySpace) jackson
59 .readValue(file2, Profile.class);
60
61 List<LinearAdditive> profiles = new LinkedList<>();
62 profiles.add(profile1);
63 profiles.add(profile2);
64 ParetoFrontier linaddpareto = new ParetoLinearAdditive(profiles);
65 System.out.println("linaddpareto result" + linaddpareto);
66 assertEquals(expectedNrPoints, linaddpareto.getPoints().size());
67
68 if (expectedNrPoints < 40) {
69 ParetoFrontier generalpareto = new GenericPareto(profiles);
70 assertEquals(generalpareto.getPoints(), linaddpareto.getPoints());
71 System.out.println("generalpareto result" + generalpareto);
72 } else {
73 System.out.println("Skippedn generalpareto - expected too slow");
74 }
75 }
76
77}
Note: See TracBrowser for help on using the repository browser.