DavidCain / mitoc-trips

The MIT Outing Club's trip management system
https://mitoc-trips.mit.edu
GNU General Public License v3.0
43 stars 9 forks source link

Proposal: Add a test for paired participants in the lottery #88

Closed billmei closed 1 year ago

billmei commented 1 year ago

Hi! In ws/tests/lottery/test_run.py, I wanted to add a test to check that paired participants are assigned correctly in the lottery algorithm.

 # david and eve are paired
david = factories.SignUpFactory.create(
    participant__pk=1024,  # Will factor into seed + ordering
    participant__name="David Davidson",
    participant__affiliation=affiliations.NON_AFFILIATE.CODE,
    trip=trip,
    on_trip=False,
)
eve = factories.SignUpFactory.create(
    participant__pk=1024,  # Will factor into seed + ordering
    participant__name="Eve Everson",
    participant__affiliation=affiliations.NON_AFFILIATE.CODE,
    trip=trip,
    on_trip=False,
)
factories.LotteryInfoFactory.create(
    participant=david, paired_with=eve
)
factories.LotteryInfoFactory.create(
    participant=eve, paired_with=david
)

However, I was having trouble running the test file—do you have any documentation for how to run it? Thanks :)

DavidCain commented 1 year ago

Hey, Bill -- there are already quite a number of tests for paired lottery participants! Namely, we have test coverage for the behavior of ranking on paired participants (and since the lottery algorithm itself only really cares about ranking, we've got decent unit test coverage). I'm not saying it tests all possible scenarios, but the goal was broadly just unit tests, and I think we have good coverage.

Can I ask what you're trying to do?

I generally don't have much documentation, since I've regarded this a solo project.

billmei commented 1 year ago

Thanks! Do you have a link to the test that checks for paired lottery participants? I couldn't find it.

I wanted to check to understand what happens if a lottery participant is paired with a leader on a trip, and whether that essentially guarantees the participant will always be selected in the lottery—I couldn't quite figure out the behavior from reading the logic alone so I figured I would try to write a test to validate that behavior :)

DavidCain commented 1 year ago

git grep 'test_.*pair' should turn up a number of examples of how pairing is tested from different angles!

I can just answer your question directly -- no, being paired with a leader does not guarantee that the participant will be placed on the trip. At trip lottery time, they'll be treated like any other participant.

If you're asking about the Winter School lottery, when two participants are paired together, it doesn't matter if one or both of them happens to be a leader -- the pairing algorithms attempts only to place them on trips where they are both signed up to be participants. For example, a WS leader could lead a hiking trip on Saturday, but then sign up as a participant (along with their paired partner) for a number of ice climbing trips on Sunday. The algorithm would try to place the two participants on their top-ranked trip on Sunday.

billmei commented 1 year ago

Gotcha, thanks! I see you had test_single_trip_pairing_lottery and test_reciprocally_paired, I was looking into adding a variation of one of those tests for when one of the participants is also a leader on the trip—but your answer also solves my question, thank you!