-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a36e0b1
commit ff97b2f
Showing
7 changed files
with
180 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/main/scala/fr/renoux/gaston/model/preferences/PersonPersonPreference.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package fr.renoux.gaston.model.preferences | ||
|
||
import fr.renoux.gaston.model._ | ||
|
||
/** Might be an anti-preference if the person really doesn't want to. */ | ||
final case class PersonPersonPreference( | ||
person: Person, | ||
targetPerson: Person, | ||
reward: Score | ||
) extends Preference.RecordLevel with Preference.Personal { | ||
|
||
override def scoreRecord(record: Record): Score = { | ||
if (record.persons.contains(person) && record.persons.contains(targetPerson)) reward | ||
else Score.Zero | ||
} | ||
|
||
override lazy val toLongString: String = s"PersonPersonPreference(${person.toShortString}, ${targetPerson.toShortString}, $reward)" | ||
|
||
override lazy val toAbstract: (String, Person.Id, Person.Id, Double) = ("PersonPersonPreference", person.id, targetPerson.id, reward.value) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/test/scala/fr/renoux/gaston/model/preferences/PersonPersonPreferenceSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package fr.renoux.gaston.model.preferences | ||
|
||
import fr.renoux.gaston.model._ | ||
import fr.renoux.gaston.util.Context | ||
import org.scalatest.flatspec.AnyFlatSpec | ||
import org.scalatest.matchers.should.Matchers | ||
|
||
// scalastyle:off magic.number | ||
class PersonPersonPreferenceSpec extends AnyFlatSpec with Matchers { | ||
|
||
import fr.renoux.gaston.MinimalTestModel.Persons._ | ||
import fr.renoux.gaston.MinimalTestModel.Problems._ | ||
import fr.renoux.gaston.MinimalTestModel.Slots._ | ||
import fr.renoux.gaston.MinimalTestModel.Topics._ | ||
|
||
private implicit val problem: Problem = Minimal | ||
private implicit val context: Context = Context.Default | ||
|
||
def scheduled(s: Slot, t: Topic, ps: Person*): Schedule = Schedule.from(s(t(ps: _*))) | ||
|
||
|
||
behavior of "PersonsPersonPreference" | ||
val leonardoLovesRaphael: Preference = PersonPersonPreference(Leonardo, Raphael, Score(42)) | ||
|
||
it should "return the score when respected" in { | ||
leonardoLovesRaphael.score(scheduled(Morning, Fighting, Leonardo, Raphael) | ||
) should be(Score(42)) | ||
} | ||
|
||
it should "return zero when not respected" in { | ||
leonardoLovesRaphael.score(scheduled(Morning, Fighting, Leonardo, Donatello) | ||
++ scheduled(Morning, Machines, Raphael, Michelangelo) | ||
) should be(Score(0)) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters