public void GetSoloEventSchedule_TwoCompetitorsSameGrade_ReturnsSameEventCount()
        {
            // Test: contest with 2 grade 4 junior competitors registered in 2 events should have 2 events
            Contest contest = this.Contest;

            contest.ContestJudges = this.OneContestJudgeList(contest);

            Competitor competitor1 = GetFakeCompetitor(1, contest, Grade.FourJunior, Instrument.Bagpipe, Idiom.Piobaireachd, Idiom.March24);
            Competitor competitor2 = GetFakeCompetitor(2, contest, Grade.FourJunior, Instrument.Bagpipe, Idiom.Piobaireachd, Idiom.March24);

            contest.Competitors = new List <Competitor> {
                competitor1, competitor2
            };

            // Call method being tested
            List <SoloEvent> result = this.service.GetSoloEventSchedule(contest);

            Assert.That(result.Count, Is.EqualTo(competitor1.RegisteredSoloEvents.Count));

            // The piob event should be 30 minutes and the non-piob should be 10
            SoloEvent piobEvent       = result.Single(x => x.Idiom == Idiom.Piobaireachd);
            SoloEvent lightMusicEvent = result.Single(x => x.Idiom != Idiom.Piobaireachd);

            Assert.That(piobEvent.DurationMinutes, Is.EqualTo(contest.Competitors.Count * Config.PiobaireachdEventDuration));
            Assert.That(lightMusicEvent.DurationMinutes, Is.EqualTo(contest.Competitors.Count * Config.LightMusicEventDuration));

            ////// The piob event should be the first event
            ////Assert.That(piobEvent.Start.Value, Is.EqualTo(contest.RegistrationOpen.Value.AddMinutes(Config.FirstEventRegistrationOpenOffset)));

            ////// The light music event cannot begin until the light music event is over
            ////Assert.That(lightMusicEvent.Start.Value, Is.EqualTo(piobEvent.Start.Value.AddMinutes(piobEvent.DurationMinutes)));
        }
예제 #2
0
        public void GetMatchingJudge_MultiplePiobJudges_ReturnsLeastBusyJudge()
        {
            // Test: Four piob judges - piob event should be assigned to the piob judge with the least amount of events in terms of time required

            // Setup here is 2 piob judges and 2 competitors registered for 2 different piob events.
            // Judge 1 (busyJudge) will be set up to already be judging the one event, so Judge 2 (availableJudge)
            // should be selected to judge the other event.
            Contest contest = this.Contest;

            contest.ContestJudges = this.GetContestJudges(contest, Instrument.Bagpipe, Idiom.Piobaireachd, Idiom.Piobaireachd);
            Judge busyJudge      = contest.ContestJudges.First().Judge;
            Judge availableJudge = contest.ContestJudges.Last().Judge;

            contest.Competitors.Add(TestBase.GetFakeCompetitor(1, contest, Grade.FourJunior, Instrument.Bagpipe, Idiom.Piobaireachd));
            contest.Competitors.Add(TestBase.GetFakeCompetitor(2, contest, Grade.FourSenior, Instrument.Bagpipe, Idiom.Piobaireachd));

            // Add the first Piob event to this judge in order to make him busy
            ContestJudge contestJudge   = contest.ContestJudges.Single(x => x.JudgeId == busyJudge.JudgeId);
            SoloEvent    busyJudgeEvent = contest.SoloEvents.Single(x => x.Idiom == Idiom.Piobaireachd && x.Grade == Grade.FourJunior);

            busyJudgeEvent.Judge = busyJudge;

            // This is the event that should get assigned to availableJudge
            SoloEvent availableJudgeEvent = contest.SoloEvents.Single(x => x.Idiom == Idiom.Piobaireachd && x.Grade == Grade.FourSenior);

            // Call the method being tested
            Judge result = this.service.GetMatchingJudge(contest, availableJudgeEvent);

            // Ensure that the judge picked for the event is the available one
            Assert.That(result.JudgeId, Is.EqualTo(availableJudge.JudgeId));
        }
예제 #3
0
        public Judge GetMatchingJudge(Contest contest, SoloEvent soloEvent)
        {
            // Is a judge already set to adjudicate this event?
            if (soloEvent.Judge != null)
            {
                // yes - find the judge
                return(contest.ContestJudges.Single(x => x.SoloEvents.Any(y => y.SoloEventId == soloEvent.SoloEventId)).Judge);
            }

            // Look for judges certified to the event who aren't already set to adjudicate it, selecting the least-busy judge
            ContestJudge contestJudge = contest.ContestJudges
                                        .OrderBy(x => x.SoloEvents.Sum(y => y.DurationMinutes))
                                        .FirstOrDefault(x => x.Judge.Instruments.Contains(soloEvent.Instrument) &&
                                                        x.Judge.Idioms.Contains(soloEvent.Idiom) &&
                                                        !x.SoloEvents.Any(y => y.SoloEventId == soloEvent.SoloEventId));

            if (contestJudge == null)
            {
                // No matching judge found
                throw new InvalidOperationException($"No judge is available to adjudicate event: {soloEvent.ToString()}");
            }

            // We found a judge.  Return him/her.
            return(contestJudge.Judge);
        }
예제 #4
0
 public void EventSolo(SoloEvent soloEvent, bool CanLeaveDiretly = true)
 {
     textLog.SetText(soloEvent.Intro);
     optionContainer.KillChildren();
     foreach (SoloSubEvent solo in soloEvent.SubEvents)
     {
         Instantiate(optionBtn, optionContainer).Setup(solo.Title).onClick.AddListener(() => EventSubSolo(solo));
     }
     Setup(CanLeaveDiretly);
 }
예제 #5
0
        public void GetMatchingJudge_ForPiobEvent_ReturnsJudge()
        {
            // Test: Contest with one piob judge - GetMatchingJudge should return that one judge
            Contest contest = this.Contest;

            contest.ContestJudges = this.OneContestJudgeList(contest);

            SoloEvent targetSoloEvent = contest.SoloEvents.First(x => x.Idiom == Idiom.Piobaireachd);

            Judge judge = this.service.GetMatchingJudge(contest, targetSoloEvent);

            Assert.That(judge.JudgeId, Is.EqualTo(contest.ContestJudges[0].JudgeId));
        }
예제 #6
0
        public void GetMatchingJudge_ExistingJudge_ReturnsJudge()
        {
            // Test: GetMatchingJudge for an event that already has a judge assigned
            Contest contest = this.Contest;

            contest.ContestJudges = this.OneContestJudgeList(contest);
            // Judge has already been assigned the Piob event
            SoloEvent soloEvent = contest.SoloEvents.First(x => x.Idiom == Idiom.Piobaireachd);

            soloEvent.Judge = contest.ContestJudges.Single().Judge;

            Judge judge = this.service.GetMatchingJudge(contest, soloEvent);

            Assert.That(judge.JudgeId, Is.EqualTo(soloEvent.Judge.JudgeId));
        }
예제 #7
0
        // Helper method that returns a Competitor instance with a populated List of SoloEventCompetitor instances matching with the given Contest
        protected static Competitor GetFakeCompetitor(int competitorId, Contest contest, Grade grade, Instrument instrument, params Idiom[] idioms)
        {
            var competitor = new Competitor {
                CompetitorId = competitorId
            };

            foreach (Idiom idiom in idioms)
            {
                SoloEvent targetSoloEvent     = contest.SoloEvents.Single(x => x.Grade == grade && x.Idiom == idiom && x.Instrument == instrument);
                var       soloEventCompetitor = new SoloEventCompetitor {
                    CompetitorId = competitorId, SoloEventId = targetSoloEvent.SoloEventId, SoloEvent = targetSoloEvent
                };
                competitor.RegisteredSoloEvents.Add(soloEventCompetitor);
                targetSoloEvent.SoloEventCompetitors.Add(soloEventCompetitor);
            }

            return(competitor);
        }