From a1c8dfabc07b5c668509a1c8a0d2718b9380f0ba Mon Sep 17 00:00:00 2001 From: av1m <36456709+av1m@users.noreply.github.com> Date: Sun, 7 Jun 2020 11:27:08 +0200 Subject: [PATCH 01/14] add QuestionPriceArea (!build) --- .../profile/QuestionPriceArea.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/main/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/QuestionPriceArea.java diff --git a/src/main/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/QuestionPriceArea.java b/src/main/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/QuestionPriceArea.java new file mode 100644 index 00000000..ff8c1e58 --- /dev/null +++ b/src/main/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/QuestionPriceArea.java @@ -0,0 +1,37 @@ +package io.github.oliviercailloux.y2018.apartments.valuefunction.profile; + +import static com.google.common.base.Preconditions.checkNotNull; + +public class QuestionPriceArea { + int price; + int surface; + private final String question = "Would you pay %d€ more for %d m2 more?"; + + private QuestionPriceArea(int price, int surface) { + checkNotNull(price); + checkNotNull(surface); + this.price = price; + this.surface = surface; + } + + public static QuestionPriceArea create(int price, int surface) { + return new QuestionPriceArea(price, surface); + } + + public int getPrice() { + return this.price; + } + + public int getSurface() { + return this.surface; + } + + public String getQuestion() { + return String.format(this.question, this.getPrice(), this.getSurface()); + } + + public void resolve(Profile p, boolean response) { + // RETURN LAVF + // p.adaptWeightRange(new range) + } +} From 134f6fb4934b9552f2864fc82bcdb81295ca67fa Mon Sep 17 00:00:00 2001 From: av1m <36456709+av1m@users.noreply.github.com> Date: Thu, 11 Jun 2020 11:46:05 +0200 Subject: [PATCH 02/14] add fake Profile class --- .../apartments/valuefunction/profile/Profile.java | 10 ++++++++++ .../valuefunction/profile/QuestionPriceArea.java | 3 +-- 2 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 src/main/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/Profile.java diff --git a/src/main/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/Profile.java b/src/main/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/Profile.java new file mode 100644 index 00000000..9d0811e5 --- /dev/null +++ b/src/main/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/Profile.java @@ -0,0 +1,10 @@ +package io.github.oliviercailloux.y2018.apartments.valuefunction.profile; + +import com.google.common.collect.Range; +import io.github.oliviercailloux.y2018.apartments.valuefunction.Criterion; + +public class Profile { + public Profile setWeightRange(Criterion crit, Range value) { + return new Profile(); + } +} diff --git a/src/main/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/QuestionPriceArea.java b/src/main/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/QuestionPriceArea.java index ff8c1e58..a4a938ee 100644 --- a/src/main/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/QuestionPriceArea.java +++ b/src/main/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/QuestionPriceArea.java @@ -31,7 +31,6 @@ public String getQuestion() { } public void resolve(Profile p, boolean response) { - // RETURN LAVF - // p.adaptWeightRange(new range) + // p.setWeightRange() } } From 8c507a801f2c4dad8b7ec4fa5d1545798e906576 Mon Sep 17 00:00:00 2001 From: clemencecousin Date: Thu, 11 Jun 2020 14:54:13 +0200 Subject: [PATCH 03/14] Creating the resolve function --- .../valuefunction/profile/Profile.java | 46 +++++++++++++++++ .../profile/QuestionPriceArea.java | 50 ++++++++++++++++++- 2 files changed, 95 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/Profile.java b/src/main/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/Profile.java index 9d0811e5..2249f099 100644 --- a/src/main/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/Profile.java +++ b/src/main/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/Profile.java @@ -1,9 +1,55 @@ package io.github.oliviercailloux.y2018.apartments.valuefunction.profile; +import static com.google.common.base.Preconditions.checkNotNull; + import com.google.common.collect.Range; import io.github.oliviercailloux.y2018.apartments.valuefunction.Criterion; public class Profile { + + private Range floorAreaWeightRange; + private Range nbBedroomsWeightRange; + private Range nbSleepingWeightRange; + private Range nbBathroomsWeightRange; + private Range terraceWeightRange; + private Range floorAreaTerraceWeightRange; + private Range wifiSubjectiveValueWeightRange; + private Range pricePerNightSubjectiveValueWeightRange; + private Range nbMinNightSubjectiveValueWeightRange; + private Range teleSubjectiveValueWeightRange; + + public Range getWeightRange(Criterion crit) { + switch (crit) { + case TELE: + return teleSubjectiveValueWeightRange; + case TERRACE: + return terraceWeightRange; + case WIFI: + return wifiSubjectiveValueWeightRange; + case FLOOR_AREA: + return floorAreaWeightRange; + case FLOOR_AREA_TERRACE: + return floorAreaTerraceWeightRange; + case NB_BATHROOMS: + return nbBathroomsWeightRange; + case NB_BEDROOMS: + return nbBedroomsWeightRange; + case NB_SLEEPING: + return nbSleepingWeightRange; + case NB_MIN_NIGHT: + return nbMinNightSubjectiveValueWeightRange; + case PRICE_PER_NIGHT: + return pricePerNightSubjectiveValueWeightRange; + default: + throw new IllegalArgumentException(); + } + } + + static double getMiddleOfRange(Range range) { + checkNotNull(range); + return (range.upperEndpoint() + range.lowerEndpoint()) / 2; + } + public Profile setWeightRange(Criterion crit, Range value) { return new Profile(); } diff --git a/src/main/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/QuestionPriceArea.java b/src/main/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/QuestionPriceArea.java index a4a938ee..7e8b4a3e 100644 --- a/src/main/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/QuestionPriceArea.java +++ b/src/main/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/QuestionPriceArea.java @@ -2,6 +2,9 @@ import static com.google.common.base.Preconditions.checkNotNull; +import com.google.common.collect.Range; +import io.github.oliviercailloux.y2018.apartments.valuefunction.Criterion; + public class QuestionPriceArea { int price; int surface; @@ -31,6 +34,51 @@ public String getQuestion() { } public void resolve(Profile p, boolean response) { - // p.setWeightRange() + Range floorAreaWeight = p.getWeightRange(Criterion.FLOOR_AREA); + Range priceWeight = p.getWeightRange(Criterion.PRICE_PER_NIGHT); + + if (response) { + + double min = + floorAreaWeight.lowerEndpoint() + Profile.getMiddleOfRange(floorAreaWeight) * 0.2; + double max = priceWeight.upperEndpoint() - Profile.getMiddleOfRange(priceWeight) * 0.1; + + if (min >= floorAreaWeight.upperEndpoint()) { + Range r = + Range.closed(floorAreaWeight.upperEndpoint(), floorAreaWeight.upperEndpoint()); + p.setWeightRange(Criterion.FLOOR_AREA, r); + } else { + Range r = Range.closed(min, floorAreaWeight.upperEndpoint()); + p.setWeightRange(Criterion.FLOOR_AREA, r); + } + if (max <= priceWeight.lowerEndpoint()) { + Range r = Range.closed(priceWeight.lowerEndpoint(), priceWeight.lowerEndpoint()); + p.setWeightRange(Criterion.PRICE_PER_NIGHT, r); + } else { + Range r = Range.closed(priceWeight.lowerEndpoint(), max); + p.setWeightRange(Criterion.PRICE_PER_NIGHT, r); + } + } else { + + double min = priceWeight.lowerEndpoint() + Profile.getMiddleOfRange(priceWeight) * 0.2; + double max = + floorAreaWeight.upperEndpoint() - Profile.getMiddleOfRange(floorAreaWeight) * 0.1; + + if (min >= priceWeight.upperEndpoint()) { + Range r = Range.closed(priceWeight.upperEndpoint(), priceWeight.upperEndpoint()); + p.setWeightRange(Criterion.PRICE_PER_NIGHT, r); + } else { + Range r = Range.closed(min, priceWeight.upperEndpoint()); + p.setWeightRange(Criterion.PRICE_PER_NIGHT, r); + } + if (max <= floorAreaWeight.lowerEndpoint()) { + Range r = + Range.closed(floorAreaWeight.lowerEndpoint(), floorAreaWeight.lowerEndpoint()); + p.setWeightRange(Criterion.FLOOR_AREA, r); + } else { + Range r = Range.closed(floorAreaWeight.lowerEndpoint(), max); + p.setWeightRange(Criterion.FLOOR_AREA, r); + } + } } } From 43ca411857a85f7475ef55928b535d53adfde310 Mon Sep 17 00:00:00 2001 From: clemencecousin Date: Thu, 11 Jun 2020 14:57:47 +0200 Subject: [PATCH 04/14] Adding JavaDoc --- .../profile/QuestionPriceArea.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/main/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/QuestionPriceArea.java b/src/main/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/QuestionPriceArea.java index 7e8b4a3e..56465fa2 100644 --- a/src/main/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/QuestionPriceArea.java +++ b/src/main/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/QuestionPriceArea.java @@ -6,10 +6,19 @@ import io.github.oliviercailloux.y2018.apartments.valuefunction.Criterion; public class QuestionPriceArea { + int price; + int surface; + private final String question = "Would you pay %d€ more for %d m2 more?"; + /** + * Instantiates a new question price/area. + * + * @param price the price shown to the user according to his/her profile + * @param surface the surface shown to the user according to his/her profile + */ private QuestionPriceArea(int price, int surface) { checkNotNull(price); checkNotNull(surface); @@ -17,6 +26,13 @@ private QuestionPriceArea(int price, int surface) { this.surface = surface; } + /** + * Creates the. + * + * @param price the price + * @param surface the surface + * @return the question price area + */ public static QuestionPriceArea create(int price, int surface) { return new QuestionPriceArea(price, surface); } @@ -33,6 +49,12 @@ public String getQuestion() { return String.format(this.question, this.getPrice(), this.getSurface()); } + /** + * Adapt the interval of weight contained in a profile depending on his response + * + * @param p the profile we need to modify + * @param response the response of the user + */ public void resolve(Profile p, boolean response) { Range floorAreaWeight = p.getWeightRange(Criterion.FLOOR_AREA); Range priceWeight = p.getWeightRange(Criterion.PRICE_PER_NIGHT); From 51390cbc0a836ca526f404fd3ff9bc517f7267ff Mon Sep 17 00:00:00 2001 From: clemencecousin Date: Thu, 11 Jun 2020 15:04:29 +0200 Subject: [PATCH 05/14] Correction typos in javadoc and creating the test class --- .../apartments/valuefunction/profile/QuestionPriceArea.java | 2 +- .../y2018/apartments/profile/QuestionPriceAreaTest.java | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 src/test/java/io/github/oliviercailloux/y2018/apartments/profile/QuestionPriceAreaTest.java diff --git a/src/main/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/QuestionPriceArea.java b/src/main/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/QuestionPriceArea.java index 56465fa2..4a947675 100644 --- a/src/main/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/QuestionPriceArea.java +++ b/src/main/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/QuestionPriceArea.java @@ -27,7 +27,7 @@ private QuestionPriceArea(int price, int surface) { } /** - * Creates the. + * Creates the question. * * @param price the price * @param surface the surface diff --git a/src/test/java/io/github/oliviercailloux/y2018/apartments/profile/QuestionPriceAreaTest.java b/src/test/java/io/github/oliviercailloux/y2018/apartments/profile/QuestionPriceAreaTest.java new file mode 100644 index 00000000..9f55a879 --- /dev/null +++ b/src/test/java/io/github/oliviercailloux/y2018/apartments/profile/QuestionPriceAreaTest.java @@ -0,0 +1,5 @@ +package io.github.oliviercailloux.y2018.apartments.profile; + +public class QuestionPriceAreaTest { + +} From a5a4c291fe7a5aecc72f9c8f5c61bb8b92cd1752 Mon Sep 17 00:00:00 2001 From: clemencecousin Date: Thu, 11 Jun 2020 15:41:11 +0200 Subject: [PATCH 06/14] Adding javadoc and unit tests --- .../profile/QuestionPriceArea.java | 4 +- .../profile/QuestionPriceAreaTest.java | 37 +++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/QuestionPriceArea.java b/src/main/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/QuestionPriceArea.java index 4a947675..cde986bd 100644 --- a/src/main/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/QuestionPriceArea.java +++ b/src/main/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/QuestionPriceArea.java @@ -27,7 +27,7 @@ private QuestionPriceArea(int price, int surface) { } /** - * Creates the question. + * Creates the object question. * * @param price the price * @param surface the surface @@ -56,6 +56,8 @@ public String getQuestion() { * @param response the response of the user */ public void resolve(Profile p, boolean response) { + + checkNotNull(p); Range floorAreaWeight = p.getWeightRange(Criterion.FLOOR_AREA); Range priceWeight = p.getWeightRange(Criterion.PRICE_PER_NIGHT); diff --git a/src/test/java/io/github/oliviercailloux/y2018/apartments/profile/QuestionPriceAreaTest.java b/src/test/java/io/github/oliviercailloux/y2018/apartments/profile/QuestionPriceAreaTest.java index 9f55a879..ea533425 100644 --- a/src/test/java/io/github/oliviercailloux/y2018/apartments/profile/QuestionPriceAreaTest.java +++ b/src/test/java/io/github/oliviercailloux/y2018/apartments/profile/QuestionPriceAreaTest.java @@ -1,5 +1,42 @@ package io.github.oliviercailloux.y2018.apartments.profile; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import io.github.oliviercailloux.y2018.apartments.valuefunction.profile.Profile; +import io.github.oliviercailloux.y2018.apartments.valuefunction.profile.QuestionPriceArea; +import org.junit.jupiter.api.Test; + public class QuestionPriceAreaTest { + /** Verifying the initialization of the object QuestionPriceArea. */ + @Test + void initializationTest() { + + QuestionPriceArea q = QuestionPriceArea.create(100, 10); + assertEquals(100, q.getPrice()); + assertEquals(10, q.getSurface()); + assertEquals("Would you pay 100€ more for 10 m2 more?", q.getQuestion()); + } + + /** + * Test if the resolve method works well. The code in comment needs the class Profile first to be + * merge to work correctly + */ + @Test + void resolveTest() { + QuestionPriceArea q = QuestionPriceArea.create(100, 10); + assertThrows(NullPointerException.class, () -> q.resolve(new Profile(), true)); + // Profile p = new Profile(); + // Range surface = Range.closed(100d, 300d); + // Range price = Range.closed(500d, 1500d); + // p.setWeightRange(Criterion.FLOOR_AREA, surface); + // p.setWeightRange(Criterion.PRICE_PER_NIGHT, price); + // q.resolve(p, false); + // assertEquals(700d, p.getWeightRange(Criterion.PRICE_PER_NIGHT).lowerEndpoint()); + // assertEquals(280d, p.getWeightRange(Criterion.FLOOR_AREA).upperEndpoint()); + // q.resolve(p, true) + // assertEquals(198d, p.getWeightRange(Criterion.FLOOR_AREA).lowerEndpoint()); + // assertEquals(1390d, p.getWeightRange(Criterion.PRICE_PER_NIGHT.upperEndpoint()); + } } From a9cd69701cd105d7d78eb064aff5ed9abfda8d45 Mon Sep 17 00:00:00 2001 From: av1m <36456709+av1m@users.noreply.github.com> Date: Thu, 11 Jun 2020 17:52:01 +0200 Subject: [PATCH 07/14] simplify resolve() function --- .../profile/QuestionPriceArea.java | 89 ++++++++++--------- 1 file changed, 45 insertions(+), 44 deletions(-) diff --git a/src/main/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/QuestionPriceArea.java b/src/main/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/QuestionPriceArea.java index cde986bd..b3ec89a8 100644 --- a/src/main/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/QuestionPriceArea.java +++ b/src/main/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/QuestionPriceArea.java @@ -6,11 +6,8 @@ import io.github.oliviercailloux.y2018.apartments.valuefunction.Criterion; public class QuestionPriceArea { - int price; - int surface; - private final String question = "Would you pay %d€ more for %d m2 more?"; /** @@ -37,14 +34,29 @@ public static QuestionPriceArea create(int price, int surface) { return new QuestionPriceArea(price, surface); } + /** + * Getter for attribute price + * + * @return the price : question parameter + */ public int getPrice() { return this.price; } + /** + * Getter for attribute surface + * + * @return the surface : question parameter + */ public int getSurface() { return this.surface; } + /** + * Build the question according to parameters emitted during class creation + * + * @return the question constructed + */ public String getQuestion() { return String.format(this.question, this.getPrice(), this.getSurface()); } @@ -56,53 +68,42 @@ public String getQuestion() { * @param response the response of the user */ public void resolve(Profile p, boolean response) { - checkNotNull(p); - Range floorAreaWeight = p.getWeightRange(Criterion.FLOOR_AREA); - Range priceWeight = p.getWeightRange(Criterion.PRICE_PER_NIGHT); - + checkNotNull(response); + Criterion firstCriterion; + Criterion secondCriterion; + Range closedRange; + + /** + * The code is very similar if the boolean response is true or false. The only factor that + * changes is the criteria. Thus, one seeks to know which criterion is given to which range. So + * we check this based on the boolean + */ if (response) { + firstCriterion = Criterion.FLOOR_AREA; + secondCriterion = Criterion.PRICE_PER_NIGHT; + } else { + secondCriterion = Criterion.FLOOR_AREA; + firstCriterion = Criterion.PRICE_PER_NIGHT; + } - double min = - floorAreaWeight.lowerEndpoint() + Profile.getMiddleOfRange(floorAreaWeight) * 0.2; - double max = priceWeight.upperEndpoint() - Profile.getMiddleOfRange(priceWeight) * 0.1; + final Range firstRange = p.getWeightRange(firstCriterion); + final Range secondRange = p.getWeightRange(secondCriterion); - if (min >= floorAreaWeight.upperEndpoint()) { - Range r = - Range.closed(floorAreaWeight.upperEndpoint(), floorAreaWeight.upperEndpoint()); - p.setWeightRange(Criterion.FLOOR_AREA, r); - } else { - Range r = Range.closed(min, floorAreaWeight.upperEndpoint()); - p.setWeightRange(Criterion.FLOOR_AREA, r); - } - if (max <= priceWeight.lowerEndpoint()) { - Range r = Range.closed(priceWeight.lowerEndpoint(), priceWeight.lowerEndpoint()); - p.setWeightRange(Criterion.PRICE_PER_NIGHT, r); - } else { - Range r = Range.closed(priceWeight.lowerEndpoint(), max); - p.setWeightRange(Criterion.PRICE_PER_NIGHT, r); - } + final double min = firstRange.lowerEndpoint() + Profile.getMiddleOfRange(firstRange) * 0.2; + if (min >= firstRange.upperEndpoint()) { + closedRange = Range.closed(firstRange.upperEndpoint(), firstRange.upperEndpoint()); } else { + closedRange = Range.closed(min, firstRange.upperEndpoint()); + } + p.setWeightRange(firstCriterion, closedRange); - double min = priceWeight.lowerEndpoint() + Profile.getMiddleOfRange(priceWeight) * 0.2; - double max = - floorAreaWeight.upperEndpoint() - Profile.getMiddleOfRange(floorAreaWeight) * 0.1; - - if (min >= priceWeight.upperEndpoint()) { - Range r = Range.closed(priceWeight.upperEndpoint(), priceWeight.upperEndpoint()); - p.setWeightRange(Criterion.PRICE_PER_NIGHT, r); - } else { - Range r = Range.closed(min, priceWeight.upperEndpoint()); - p.setWeightRange(Criterion.PRICE_PER_NIGHT, r); - } - if (max <= floorAreaWeight.lowerEndpoint()) { - Range r = - Range.closed(floorAreaWeight.lowerEndpoint(), floorAreaWeight.lowerEndpoint()); - p.setWeightRange(Criterion.FLOOR_AREA, r); - } else { - Range r = Range.closed(floorAreaWeight.lowerEndpoint(), max); - p.setWeightRange(Criterion.FLOOR_AREA, r); - } + final double max = secondRange.upperEndpoint() - Profile.getMiddleOfRange(secondRange) * 0.1; + if (max <= secondRange.lowerEndpoint()) { + closedRange = Range.closed(secondRange.lowerEndpoint(), secondRange.lowerEndpoint()); + } else { + closedRange = Range.closed(secondRange.lowerEndpoint(), max); } + p.setWeightRange(secondCriterion, closedRange); } } From f3147a8c1468d62bc16b9cddc0d72e53993ed3d6 Mon Sep 17 00:00:00 2001 From: av1m <36456709+av1m@users.noreply.github.com> Date: Wed, 17 Jun 2020 14:24:12 +0200 Subject: [PATCH 08/14] finalize resolve() --- .../profile/QuestionPriceArea.java | 4 +- .../profile/QuestionPriceAreaTest.java | 42 ---------------- .../profile/QuestionPriceAreaTests.java | 49 +++++++++++++++++++ .../valuefunction/profile/ProfileTest.java | 4 +- 4 files changed, 52 insertions(+), 47 deletions(-) delete mode 100644 src/test/java/io/github/oliviercailloux/y2018/apartments/profile/QuestionPriceAreaTest.java create mode 100644 src/test/java/io/github/oliviercailloux/y2018/apartments/profile/QuestionPriceAreaTests.java diff --git a/src/main/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/QuestionPriceArea.java b/src/main/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/QuestionPriceArea.java index b3ec89a8..19ba5600 100644 --- a/src/main/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/QuestionPriceArea.java +++ b/src/main/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/QuestionPriceArea.java @@ -90,7 +90,7 @@ public void resolve(Profile p, boolean response) { final Range firstRange = p.getWeightRange(firstCriterion); final Range secondRange = p.getWeightRange(secondCriterion); - final double min = firstRange.lowerEndpoint() + Profile.getMiddleOfRange(firstRange) * 0.2; + final double min = firstRange.lowerEndpoint() + p.getMiddleOfRange(firstCriterion) * 0.2; if (min >= firstRange.upperEndpoint()) { closedRange = Range.closed(firstRange.upperEndpoint(), firstRange.upperEndpoint()); } else { @@ -98,7 +98,7 @@ public void resolve(Profile p, boolean response) { } p.setWeightRange(firstCriterion, closedRange); - final double max = secondRange.upperEndpoint() - Profile.getMiddleOfRange(secondRange) * 0.1; + final double max = secondRange.upperEndpoint() - p.getMiddleOfRange(secondCriterion) * 0.1; if (max <= secondRange.lowerEndpoint()) { closedRange = Range.closed(secondRange.lowerEndpoint(), secondRange.lowerEndpoint()); } else { diff --git a/src/test/java/io/github/oliviercailloux/y2018/apartments/profile/QuestionPriceAreaTest.java b/src/test/java/io/github/oliviercailloux/y2018/apartments/profile/QuestionPriceAreaTest.java deleted file mode 100644 index ea533425..00000000 --- a/src/test/java/io/github/oliviercailloux/y2018/apartments/profile/QuestionPriceAreaTest.java +++ /dev/null @@ -1,42 +0,0 @@ -package io.github.oliviercailloux.y2018.apartments.profile; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; - -import io.github.oliviercailloux.y2018.apartments.valuefunction.profile.Profile; -import io.github.oliviercailloux.y2018.apartments.valuefunction.profile.QuestionPriceArea; -import org.junit.jupiter.api.Test; - -public class QuestionPriceAreaTest { - - /** Verifying the initialization of the object QuestionPriceArea. */ - @Test - void initializationTest() { - - QuestionPriceArea q = QuestionPriceArea.create(100, 10); - assertEquals(100, q.getPrice()); - assertEquals(10, q.getSurface()); - assertEquals("Would you pay 100€ more for 10 m2 more?", q.getQuestion()); - } - - /** - * Test if the resolve method works well. The code in comment needs the class Profile first to be - * merge to work correctly - */ - @Test - void resolveTest() { - QuestionPriceArea q = QuestionPriceArea.create(100, 10); - assertThrows(NullPointerException.class, () -> q.resolve(new Profile(), true)); - // Profile p = new Profile(); - // Range surface = Range.closed(100d, 300d); - // Range price = Range.closed(500d, 1500d); - // p.setWeightRange(Criterion.FLOOR_AREA, surface); - // p.setWeightRange(Criterion.PRICE_PER_NIGHT, price); - // q.resolve(p, false); - // assertEquals(700d, p.getWeightRange(Criterion.PRICE_PER_NIGHT).lowerEndpoint()); - // assertEquals(280d, p.getWeightRange(Criterion.FLOOR_AREA).upperEndpoint()); - // q.resolve(p, true) - // assertEquals(198d, p.getWeightRange(Criterion.FLOOR_AREA).lowerEndpoint()); - // assertEquals(1390d, p.getWeightRange(Criterion.PRICE_PER_NIGHT.upperEndpoint()); - } -} diff --git a/src/test/java/io/github/oliviercailloux/y2018/apartments/profile/QuestionPriceAreaTests.java b/src/test/java/io/github/oliviercailloux/y2018/apartments/profile/QuestionPriceAreaTests.java new file mode 100644 index 00000000..73a77a6e --- /dev/null +++ b/src/test/java/io/github/oliviercailloux/y2018/apartments/profile/QuestionPriceAreaTests.java @@ -0,0 +1,49 @@ +package io.github.oliviercailloux.y2018.apartments.profile; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import com.google.common.collect.Range; +import io.github.oliviercailloux.y2018.apartments.valuefunction.Criterion; +import io.github.oliviercailloux.y2018.apartments.valuefunction.profile.Profile; +import io.github.oliviercailloux.y2018.apartments.valuefunction.profile.QuestionPriceArea; +import java.util.Arrays; +import org.junit.jupiter.api.Test; + +public class QuestionPriceAreaTests { + + /** Verifying the initialization of the object QuestionPriceArea. */ + @Test + void testInitialization() { + QuestionPriceArea q = QuestionPriceArea.create(100, 10); + assertEquals(100, q.getPrice()); + assertEquals(10, q.getSurface()); + assertEquals("Would you pay 100€ more for 10 m2 more?", q.getQuestion()); + } + + /** + * Test if the resolve method works well. The code in comment needs the class Profile first to be + * merge to work correctly + */ + @Test + void testResolve() { + QuestionPriceArea q = QuestionPriceArea.create(100, 10); + assertThrows(NullPointerException.class, () -> q.resolve(new Profile.Builder().build(), true)); + // Profile construction + Range surface = Range.closed(100d, 300d); + Range price = Range.closed(500d, 1500d); + Profile.Builder profileBuilder = new Profile.Builder(); + Arrays.stream(Criterion.values()) + .forEach(c -> profileBuilder.setWeightRange(c, Range.closed(0d, 10d))); + profileBuilder + .setWeightRange(Criterion.FLOOR_AREA, surface.lowerEndpoint(), surface.upperEndpoint()) + .setWeightRange(Criterion.PRICE_PER_NIGHT, price.lowerEndpoint(), price.upperEndpoint()); + Profile p = profileBuilder.build(); + q.resolve(p, false); + assertEquals(700d, p.getWeightRange(Criterion.PRICE_PER_NIGHT).lowerEndpoint()); + assertEquals(280d, p.getWeightRange(Criterion.FLOOR_AREA).upperEndpoint()); + q.resolve(p, true); + assertEquals(138d, p.getWeightRange(Criterion.FLOOR_AREA).lowerEndpoint()); + assertEquals(1390d, p.getWeightRange(Criterion.PRICE_PER_NIGHT).upperEndpoint()); + } +} diff --git a/src/test/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/ProfileTest.java b/src/test/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/ProfileTest.java index d5c4626c..c25931f3 100644 --- a/src/test/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/ProfileTest.java +++ b/src/test/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/ProfileTest.java @@ -47,9 +47,7 @@ void initEach() { @Test void profileTest() { assertEquals(2d, profile.getLinearAVF().getWeight(Criterion.FLOOR_AREA), 0.0001); - assertEquals( - Range.closed(0d, 10d), - profile.getWeightRange(Criterion.NB_BEDROOMS)); + assertEquals(Range.closed(0d, 10d), profile.getWeightRange(Criterion.NB_BEDROOMS)); } /** Function to test the Profile builder */ From 9bd19d4d2a38fd2bfa9b22edacf23f518a4c436f Mon Sep 17 00:00:00 2001 From: av1m <36456709+av1m@users.noreply.github.com> Date: Wed, 17 Jun 2020 14:53:40 +0200 Subject: [PATCH 09/14] move questionPriceAreaTests to valuefunction.profile --- .../{ => valuefunction}/profile/QuestionPriceAreaTests.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) rename src/test/java/io/github/oliviercailloux/y2018/apartments/{ => valuefunction}/profile/QuestionPriceAreaTests.java (89%) diff --git a/src/test/java/io/github/oliviercailloux/y2018/apartments/profile/QuestionPriceAreaTests.java b/src/test/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/QuestionPriceAreaTests.java similarity index 89% rename from src/test/java/io/github/oliviercailloux/y2018/apartments/profile/QuestionPriceAreaTests.java rename to src/test/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/QuestionPriceAreaTests.java index 73a77a6e..9fb55ced 100644 --- a/src/test/java/io/github/oliviercailloux/y2018/apartments/profile/QuestionPriceAreaTests.java +++ b/src/test/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/QuestionPriceAreaTests.java @@ -1,12 +1,10 @@ -package io.github.oliviercailloux.y2018.apartments.profile; +package io.github.oliviercailloux.y2018.apartments.valuefunction.profile; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import com.google.common.collect.Range; import io.github.oliviercailloux.y2018.apartments.valuefunction.Criterion; -import io.github.oliviercailloux.y2018.apartments.valuefunction.profile.Profile; -import io.github.oliviercailloux.y2018.apartments.valuefunction.profile.QuestionPriceArea; import java.util.Arrays; import org.junit.jupiter.api.Test; From 5cb20dc6dd6f860db028a2a910b1575f02bdd942 Mon Sep 17 00:00:00 2001 From: av1m <36456709+av1m@users.noreply.github.com> Date: Wed, 17 Jun 2020 15:26:46 +0200 Subject: [PATCH 10/14] remove checkNotNull for int and boolean --- .../apartments/valuefunction/profile/QuestionPriceArea.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/QuestionPriceArea.java b/src/main/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/QuestionPriceArea.java index 19ba5600..a4315940 100644 --- a/src/main/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/QuestionPriceArea.java +++ b/src/main/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/QuestionPriceArea.java @@ -17,8 +17,6 @@ public class QuestionPriceArea { * @param surface the surface shown to the user according to his/her profile */ private QuestionPriceArea(int price, int surface) { - checkNotNull(price); - checkNotNull(surface); this.price = price; this.surface = surface; } @@ -69,7 +67,6 @@ public String getQuestion() { */ public void resolve(Profile p, boolean response) { checkNotNull(p); - checkNotNull(response); Criterion firstCriterion; Criterion secondCriterion; Range closedRange; From 7c916915ee4778efa9494da1165860554ec313bc Mon Sep 17 00:00:00 2001 From: av1m <36456709+av1m@users.noreply.github.com> Date: Fri, 19 Jun 2020 17:45:13 +0200 Subject: [PATCH 11/14] minor fix --- .../valuefunction/profile/QuestionPriceArea.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/QuestionPriceArea.java b/src/main/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/QuestionPriceArea.java index a4315940..4acb337d 100644 --- a/src/main/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/QuestionPriceArea.java +++ b/src/main/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/QuestionPriceArea.java @@ -6,8 +6,8 @@ import io.github.oliviercailloux.y2018.apartments.valuefunction.Criterion; public class QuestionPriceArea { - int price; - int surface; + private int price; + private int surface; private final String question = "Would you pay %d€ more for %d m2 more?"; /** @@ -33,16 +33,16 @@ public static QuestionPriceArea create(int price, int surface) { } /** - * Getter for attribute price + * Getter for attribute price Price unit: euro (€) * - * @return the price : question parameter + * @return the price: question parameter */ public int getPrice() { return this.price; } /** - * Getter for attribute surface + * Getter for attribute surface Surface unit: square meter * * @return the surface : question parameter */ From bb5083a990b940711ebe72a96a19e51adc0ed082 Mon Sep 17 00:00:00 2001 From: av1m <36456709+av1m@users.noreply.github.com> Date: Sun, 21 Jun 2020 01:03:39 +0200 Subject: [PATCH 12/14] use Math.min() and Math.max() instead of if statement --- .../valuefunction/profile/QuestionPriceArea.java | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/main/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/QuestionPriceArea.java b/src/main/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/QuestionPriceArea.java index 4acb337d..e9bac835 100644 --- a/src/main/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/QuestionPriceArea.java +++ b/src/main/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/QuestionPriceArea.java @@ -63,7 +63,7 @@ public String getQuestion() { * Adapt the interval of weight contained in a profile depending on his response * * @param p the profile we need to modify - * @param response the response of the user + * @param response the response of the user to the question */ public void resolve(Profile p, boolean response) { checkNotNull(p); @@ -88,19 +88,11 @@ public void resolve(Profile p, boolean response) { final Range secondRange = p.getWeightRange(secondCriterion); final double min = firstRange.lowerEndpoint() + p.getMiddleOfRange(firstCriterion) * 0.2; - if (min >= firstRange.upperEndpoint()) { - closedRange = Range.closed(firstRange.upperEndpoint(), firstRange.upperEndpoint()); - } else { - closedRange = Range.closed(min, firstRange.upperEndpoint()); - } + closedRange = Range.closed(Math.min(min, firstRange.upperEndpoint()), firstRange.upperEndpoint()); p.setWeightRange(firstCriterion, closedRange); final double max = secondRange.upperEndpoint() - p.getMiddleOfRange(secondCriterion) * 0.1; - if (max <= secondRange.lowerEndpoint()) { - closedRange = Range.closed(secondRange.lowerEndpoint(), secondRange.lowerEndpoint()); - } else { - closedRange = Range.closed(secondRange.lowerEndpoint(), max); - } + closedRange = Range.closed(secondRange.lowerEndpoint(), Math.max(max, secondRange.lowerEndpoint())); p.setWeightRange(secondCriterion, closedRange); } } From b732125494e62b6b3867be6228ce210389c5df5b Mon Sep 17 00:00:00 2001 From: EtienneCartier Date: Tue, 23 Jun 2020 10:26:30 +0200 Subject: [PATCH 13/14] Add of the rate computing --- .../profile/QuestionPriceArea.java | 30 +++++++++++++++++-- .../profile/ProfileManagerTest.java | 1 + 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/QuestionPriceArea.java b/src/main/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/QuestionPriceArea.java index e9bac835..104bff71 100644 --- a/src/main/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/QuestionPriceArea.java +++ b/src/main/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/QuestionPriceArea.java @@ -71,15 +71,37 @@ public void resolve(Profile p, boolean response) { Criterion secondCriterion; Range closedRange; + double surfaceR; + double priceR; + double rate; + + Range surfaceRange; + Range priceRange; + + /** In this part we compute the different rates of increasment the question is proposing. */ + surfaceRange = p.getLinearAVF().getFloorAreaValueFunction().getInterval(); + surfaceR = + this.surface + / (surfaceRange.upperEndpoint().doubleValue() + - surfaceRange.lowerEndpoint().doubleValue()); + + priceRange = p.getLinearAVF().getPricePerNightValueFunction().getInterval(); + priceR = + this.price + / (priceRange.upperEndpoint().doubleValue() - priceRange.lowerEndpoint().doubleValue()); + /** * The code is very similar if the boolean response is true or false. The only factor that * changes is the criteria. Thus, one seeks to know which criterion is given to which range. So - * we check this based on the boolean + * we check this based on the boolean. This also allow us to compute the rate we will be using + * to adapt the non-prioritized range. */ if (response) { + rate = priceR / surfaceR; firstCriterion = Criterion.FLOOR_AREA; secondCriterion = Criterion.PRICE_PER_NIGHT; } else { + rate = surfaceR / priceR; secondCriterion = Criterion.FLOOR_AREA; firstCriterion = Criterion.PRICE_PER_NIGHT; } @@ -88,11 +110,13 @@ public void resolve(Profile p, boolean response) { final Range secondRange = p.getWeightRange(secondCriterion); final double min = firstRange.lowerEndpoint() + p.getMiddleOfRange(firstCriterion) * 0.2; - closedRange = Range.closed(Math.min(min, firstRange.upperEndpoint()), firstRange.upperEndpoint()); + closedRange = + Range.closed(Math.min(min, firstRange.upperEndpoint()), firstRange.upperEndpoint()); p.setWeightRange(firstCriterion, closedRange); final double max = secondRange.upperEndpoint() - p.getMiddleOfRange(secondCriterion) * 0.1; - closedRange = Range.closed(secondRange.lowerEndpoint(), Math.max(max, secondRange.lowerEndpoint())); + closedRange = + Range.closed(secondRange.lowerEndpoint(), Math.max(max, secondRange.lowerEndpoint())); p.setWeightRange(secondCriterion, closedRange); } } diff --git a/src/test/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/ProfileManagerTest.java b/src/test/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/ProfileManagerTest.java index e979b3cb..6875724b 100644 --- a/src/test/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/ProfileManagerTest.java +++ b/src/test/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/ProfileManagerTest.java @@ -1,6 +1,7 @@ package io.github.oliviercailloux.y2018.apartments.valuefunction.profile; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; + import org.junit.jupiter.api.Test; public class ProfileManagerTest { From 8a58efaa8ef9b887adbf5e4d4a7cac80a060df19 Mon Sep 17 00:00:00 2001 From: av1m <36456709+av1m@users.noreply.github.com> Date: Sun, 28 Jun 2020 18:07:14 +0200 Subject: [PATCH 14/14] update resolve() --- .../apartments/valuefunction/LinearAVF.java | 6 +- .../profile/QuestionPriceArea.java | 60 +++++++------------ .../profile/QuestionPriceAreaTests.java | 29 +++------ 3 files changed, 35 insertions(+), 60 deletions(-) diff --git a/src/main/java/io/github/oliviercailloux/y2018/apartments/valuefunction/LinearAVF.java b/src/main/java/io/github/oliviercailloux/y2018/apartments/valuefunction/LinearAVF.java index 908bd355..ba412112 100644 --- a/src/main/java/io/github/oliviercailloux/y2018/apartments/valuefunction/LinearAVF.java +++ b/src/main/java/io/github/oliviercailloux/y2018/apartments/valuefunction/LinearAVF.java @@ -273,7 +273,7 @@ private void setInternalValueFunction(Criterion criterion, ReversedLinearValueFu * want to obtain * @return the BooleanValueFunction associated with criterion */ - private BooleanValueFunction getInternalBooleanValueFunction(Criterion criterion) { + public BooleanValueFunction getInternalBooleanValueFunction(Criterion criterion) { checkNotNull(criterion); checkArgument(criterion.hasBooleanDomain()); return this.booleanValueFunctions.get(criterion); @@ -287,7 +287,7 @@ private BooleanValueFunction getInternalBooleanValueFunction(Criterion criterion * want to obtain * @return the LinearValueFunction associated with criterion */ - private LinearValueFunction getInternalLinearValueFunction(Criterion criterion) { + public LinearValueFunction getInternalLinearValueFunction(Criterion criterion) { checkNotNull(criterion); checkArgument(criterion.isDoubleCrescent()); return this.linearValueFunctions.get(criterion); @@ -301,7 +301,7 @@ private LinearValueFunction getInternalLinearValueFunction(Criterion criterion) * that we want to obtain * @return the ReversedLinearValueFunction associated with criterion */ - private ReversedLinearValueFunction getInternalReversedLinearValueFunction(Criterion criterion) { + public ReversedLinearValueFunction getInternalReversedLinearValueFunction(Criterion criterion) { checkNotNull(criterion); checkArgument(criterion.isDoubleDecrease()); return this.reversedValueFunctions.get(criterion); diff --git a/src/main/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/QuestionPriceArea.java b/src/main/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/QuestionPriceArea.java index 104bff71..7f4b4a29 100644 --- a/src/main/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/QuestionPriceArea.java +++ b/src/main/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/QuestionPriceArea.java @@ -4,6 +4,7 @@ import com.google.common.collect.Range; import io.github.oliviercailloux.y2018.apartments.valuefunction.Criterion; +import java.util.EnumMap; public class QuestionPriceArea { private int price; @@ -64,59 +65,44 @@ public String getQuestion() { * * @param p the profile we need to modify * @param response the response of the user to the question + * @return Profile containing the old profile with the Floor Area modified weight */ - public void resolve(Profile p, boolean response) { + public Profile resolve(Profile p, boolean response) { checkNotNull(p); - Criterion firstCriterion; - Criterion secondCriterion; - Range closedRange; - - double surfaceR; - double priceR; double rate; - - Range surfaceRange; - Range priceRange; + Range closedRange; + EnumMap> profileWeights = new EnumMap<>(p.getWeightsRange()); /** In this part we compute the different rates of increasment the question is proposing. */ - surfaceRange = p.getLinearAVF().getFloorAreaValueFunction().getInterval(); - surfaceR = + Range surfaceRange = + p.getLinearAVF().getInternalLinearValueFunction(Criterion.FLOOR_AREA).getInterval(); + double surfaceR = this.surface / (surfaceRange.upperEndpoint().doubleValue() - surfaceRange.lowerEndpoint().doubleValue()); - priceRange = p.getLinearAVF().getPricePerNightValueFunction().getInterval(); - priceR = + Range priceRange = + p.getLinearAVF() + .getInternalReversedLinearValueFunction(Criterion.PRICE_PER_NIGHT) + .getInterval(); + double priceR = this.price / (priceRange.upperEndpoint().doubleValue() - priceRange.lowerEndpoint().doubleValue()); - /** - * The code is very similar if the boolean response is true or false. The only factor that - * changes is the criteria. Thus, one seeks to know which criterion is given to which range. So - * we check this based on the boolean. This also allow us to compute the rate we will be using - * to adapt the non-prioritized range. - */ if (response) { rate = priceR / surfaceR; - firstCriterion = Criterion.FLOOR_AREA; - secondCriterion = Criterion.PRICE_PER_NIGHT; + closedRange = + Range.closed( + Math.min(rate, p.getWeightRange(Criterion.FLOOR_AREA).upperEndpoint()), + p.getWeightRange(Criterion.FLOOR_AREA).upperEndpoint()); } else { rate = surfaceR / priceR; - secondCriterion = Criterion.FLOOR_AREA; - firstCriterion = Criterion.PRICE_PER_NIGHT; + closedRange = + Range.closed( + p.getWeightRange(Criterion.FLOOR_AREA).lowerEndpoint(), + Math.max(rate, p.getWeightRange(Criterion.FLOOR_AREA).lowerEndpoint())); } - - final Range firstRange = p.getWeightRange(firstCriterion); - final Range secondRange = p.getWeightRange(secondCriterion); - - final double min = firstRange.lowerEndpoint() + p.getMiddleOfRange(firstCriterion) * 0.2; - closedRange = - Range.closed(Math.min(min, firstRange.upperEndpoint()), firstRange.upperEndpoint()); - p.setWeightRange(firstCriterion, closedRange); - - final double max = secondRange.upperEndpoint() - p.getMiddleOfRange(secondCriterion) * 0.1; - closedRange = - Range.closed(secondRange.lowerEndpoint(), Math.max(max, secondRange.lowerEndpoint())); - p.setWeightRange(secondCriterion, closedRange); + profileWeights.put(Criterion.FLOOR_AREA, closedRange); + return Profile.create(profileWeights, p.getLinearAVF()); } } diff --git a/src/test/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/QuestionPriceAreaTests.java b/src/test/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/QuestionPriceAreaTests.java index 9fb55ced..333a654d 100644 --- a/src/test/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/QuestionPriceAreaTests.java +++ b/src/test/java/io/github/oliviercailloux/y2018/apartments/valuefunction/profile/QuestionPriceAreaTests.java @@ -1,11 +1,9 @@ package io.github.oliviercailloux.y2018.apartments.valuefunction.profile; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; import com.google.common.collect.Range; import io.github.oliviercailloux.y2018.apartments.valuefunction.Criterion; -import java.util.Arrays; import org.junit.jupiter.api.Test; public class QuestionPriceAreaTests { @@ -25,23 +23,14 @@ void testInitialization() { */ @Test void testResolve() { - QuestionPriceArea q = QuestionPriceArea.create(100, 10); - assertThrows(NullPointerException.class, () -> q.resolve(new Profile.Builder().build(), true)); - // Profile construction - Range surface = Range.closed(100d, 300d); - Range price = Range.closed(500d, 1500d); - Profile.Builder profileBuilder = new Profile.Builder(); - Arrays.stream(Criterion.values()) - .forEach(c -> profileBuilder.setWeightRange(c, Range.closed(0d, 10d))); - profileBuilder - .setWeightRange(Criterion.FLOOR_AREA, surface.lowerEndpoint(), surface.upperEndpoint()) - .setWeightRange(Criterion.PRICE_PER_NIGHT, price.lowerEndpoint(), price.upperEndpoint()); - Profile p = profileBuilder.build(); - q.resolve(p, false); - assertEquals(700d, p.getWeightRange(Criterion.PRICE_PER_NIGHT).lowerEndpoint()); - assertEquals(280d, p.getWeightRange(Criterion.FLOOR_AREA).upperEndpoint()); - q.resolve(p, true); - assertEquals(138d, p.getWeightRange(Criterion.FLOOR_AREA).lowerEndpoint()); - assertEquals(1390d, p.getWeightRange(Criterion.PRICE_PER_NIGHT).upperEndpoint()); + QuestionPriceArea question = QuestionPriceArea.create(15, 5); + Profile profile = ProfileManager.getInstance().getProfile(ProfileType.STUDENT); + Profile profile1 = question.resolve(profile, false); + assertEquals(0.1234d, profile1.getWeightRange(Criterion.FLOOR_AREA).upperEndpoint(), 0.0001); + assertEquals(0.0d, profile1.getWeightRange(Criterion.FLOOR_AREA).lowerEndpoint()); + Profile profile2 = question.resolve(profile, true); + assertEquals(Range.closed(8.1d, 15.0d), profile2.getWeightRange(Criterion.FLOOR_AREA)); + assertEquals(15.0d, profile2.getWeightRange(Criterion.FLOOR_AREA).upperEndpoint(), 0.0001); + assertEquals(8.1d, profile2.getWeightRange(Criterion.FLOOR_AREA).lowerEndpoint(), 0.0001); } }