예제 #1
0
        public void CompareTo_ShouldConsiderPernalties()
        {
            Beacon martijnBeacon = new Beacon(new byte[] { 0, 0, 0, 0, 0, 1 }, 2);
            Rider  martijn       = new Rider("Martijn", martijnBeacon);

            //make a fast lap with loads of penalties
            IdEvent     startId     = new IdEvent(DateTime.Now, martijn, "StartId", Direction.Enter);
            TimingEvent startTiming = new TimingEvent(DateTime.Now, martijn, 100, 0);
            IdEvent     endId       = new IdEvent(DateTime.Now, martijn, "EndId", Direction.Enter);
            TimingEvent endTiming   = new TimingEvent(DateTime.Now, martijn, 200, 1);

            FinishedEvent fastFinish = new FinishedEvent(startId, startTiming, endTiming, endId);

            Lap fast = new Lap(fastFinish);

            fast.AddPenalties(new List <PenaltyEvent>
            {
                new PenaltyEvent(DateTime.Now, martijn, "reason", 1, "staff"),
                new PenaltyEvent(DateTime.Now, martijn, "reason", 2, "staff")
            });

            //make a slower lap without penalties
            IdEvent     slowStartId     = new IdEvent(DateTime.Now, martijn, "StartId", Direction.Enter);
            TimingEvent slowStartTiming = new TimingEvent(DateTime.Now, martijn, 100, 0);
            IdEvent     slowEndId       = new IdEvent(DateTime.Now, martijn, "EndId", Direction.Enter);
            TimingEvent slowEndTiming   = new TimingEvent(DateTime.Now, martijn, 300, 1);

            FinishedEvent slowFinish = new FinishedEvent(slowStartId, slowStartTiming, slowEndTiming, slowEndId);

            Lap slow = new Lap(slowFinish);

            //without penalties the lap time should dictate the ordering
            Assert.AreEqual(1, slow.CompareTo(fast, false));
            Assert.AreEqual(-1, fast.CompareTo(slow, false));

            //with penalties the slower lap is actually faster
            Assert.AreEqual(-1, slow.CompareTo(fast, true));
            Assert.AreEqual(1, fast.CompareTo(slow, true));

            //the default should take penalties into account
            Assert.AreEqual(-1, slow.CompareTo(fast));
            Assert.AreEqual(1, fast.CompareTo(slow));
        }