public void TestIntegration() { const string a = "A"; const string b = "B"; const string c = "C"; const string d = "D"; var history = new[] { new Occurrence(DateTime.UtcNow.AddDays(-1), new[] { new[] { a, b }, new[] { c, d } }), new Occurrence(DateTime.UtcNow.AddDays(-2), new[] { new[] { a, c }, new[] { b, d } }) }; var scorer = new HistoryBasedScorer(history); var generator = new AllCombinationOccurrenceGenerator { Individuals = new[] { a, b, c, d }, TargetGroupingCount = 2 }; var picker = new OccurrencePicker(generator, scorer); var occurrence = picker.PickBestOccurrence(); Assert.That(occurrence.Groupings.ToList(), Has.Count.EqualTo(2)); Assert.That(occurrence.Groupings.Any(x => x.Contains(a) && x.Contains(d)), $"{a} should meet with {d}"); Assert.That(occurrence.Groupings.Any(x => x.Contains(b) && x.Contains(c)), $"{b} should meet with {c}"); }
public void TestScorePairing() { const string a = "A"; const string b = "B"; const string c = "C"; const string d = "D"; const string e = "E"; const string f = "F"; var history = new[] { new Occurrence(DateTime.UtcNow.AddDays(-1), new[] { new[] { a, b }, new[] { c, d }, new[] { e, f } }), new Occurrence(DateTime.UtcNow.AddDays(-2), new[] { new[] { a, f }, new[] { c, b }, new[] { e, d } }), new Occurrence(DateTime.UtcNow.AddDays(-3), new[] { new[] { a, d }, new[] { c, f }, new[] { e, b } }) }; int?rank = null; // we use this variable to capture the input to WeightFunction so we can check its value var scorer = new HistoryBasedScorer(history) { WeightFunction = i => { rank = i; return(i * 2d); } }; Assert.That(scorer.ScorePairing(a, b), Is.Zero); Assert.That(rank, Is.Zero); Assert.That(scorer.ScorePairing(a, f), Is.EqualTo(2d)); Assert.That(rank, Is.EqualTo(1d)); Assert.That(scorer.ScorePairing(a, d), Is.EqualTo(4d)); Assert.That(rank, Is.EqualTo(2d)); Assert.That(scorer.ScorePairing(a, a), Is.EqualTo(6d)); Assert.That(rank, Is.EqualTo(3d)); Assert.That(scorer.ScorePairing(a, c), Is.EqualTo(6d)); Assert.That(rank, Is.EqualTo(3d)); Assert.That(scorer.ScorePairing("foo", a), Is.Zero); Assert.That(rank, Is.Zero); Assert.That(scorer.ScorePairing("foo", "bar"), Is.Zero); Assert.That(rank, Is.Zero); }
static void Main() { var history = ReadHistory(); var roommates = ReadRoommates(); var individuals = ReadIndividuals(); var occurrenceGenerator = new AllCombinationOccurrenceGenerator { Individuals = new ReadOnlyCollection <string>(individuals), ExemptMeetings = roommates }; var scorer = new HistoryBasedScorer(history); var splitter = new OccurrencePicker(occurrenceGenerator, scorer); var occurrence = splitter.PickBestOccurrence(); WriteOccurrenceToConsole(occurrence); history.Add(occurrence); WriteHistory(history); }