Пример #1
0
        public void AddLapAndGetAllLaps_ManyLaps()
        {
            int      days = 0, hours = 0, minutes = 3, seconds = 14, millis = 791;
            TimeSpan lap1Time = new TimeSpan(days, hours, minutes, seconds, millis);
            TimeSpan lap2Time = new TimeSpan(days, hours, minutes, seconds, millis + 10);
            TimeSpan lap3Time = new TimeSpan(days, hours, minutes, seconds + 1, millis);
            TimeSpan lap4Time = new TimeSpan(days, hours, minutes + 1, seconds, millis);
            TimeSpan lap5Time = new TimeSpan(days, hours, minutes, seconds, millis + 250);

            _lapTimer.AddLap(lap1Time);
            _lapTimer.AddLap(lap2Time);
            _lapTimer.AddLap(lap3Time);
            _lapTimer.AddLap(lap4Time);
            _lapTimer.AddLap(lap5Time);

            List <Lap> allLaps = _lapTimer.GetAllLaps();

            Assert.Equal(1, allLaps[0].Number);
            Assert.Equal(lap1Time, allLaps[0].Time);

            Assert.Equal(2, allLaps[1].Number);
            Assert.Equal(lap2Time, allLaps[1].Time);

            Assert.Equal(3, allLaps[2].Number);
            Assert.Equal(lap3Time, allLaps[2].Time);

            Assert.Equal(4, allLaps[3].Number);
            Assert.Equal(lap4Time, allLaps[3].Time);

            Assert.Equal(5, allLaps[4].Number);
            Assert.Equal(lap5Time, allLaps[4].Time);
        }
        public void AddLapResult_OneTimerAndManyResults()
        {
            IPAddress address = IPAddress.Parse("1.1.1.1");

            _lapTimerManager.RegisterLapTimer(address);
            int      days = 0, hours = 0, minutes = 3, seconds = 14, millis = 791;
            TimeSpan time1 = new TimeSpan(days, hours, minutes, seconds, millis);
            TimeSpan time2 = new TimeSpan(days, hours, minutes, seconds, millis + 10);
            TimeSpan time3 = new TimeSpan(days, hours, minutes, seconds + 1, millis);

            _lapTimerManager.AddLapResult(address, time1);
            _lapTimerManager.AddLapResult(address, time2);
            _lapTimerManager.AddLapResult(address, time3);

            LapTimer timer = _lapTimerManager.GetLapTimerByIPAddress(address);

            Assert.NotNull(timer);
            var addedLaps = timer.GetAllLaps();

            Assert.Equal(1, addedLaps[0].Number);
            Assert.Equal(2, addedLaps[1].Number);
            Assert.Equal(3, addedLaps[2].Number);
            Assert.Equal(time1, addedLaps[0].Time);
            Assert.Equal(time2, addedLaps[1].Time);
            Assert.Equal(time3, addedLaps[2].Time);
        }
        public void AddLapResult_MultipleTimersAndMultipleResults()
        {
            IPAddress timer1Address = IPAddress.Parse("1.1.1.1");
            IPAddress timer2Address = IPAddress.Parse("2.2.2.2");

            _lapTimerManager.RegisterLapTimer(timer1Address);
            _lapTimerManager.RegisterLapTimer(timer2Address);

            int      days = 0, hours = 0, minutes = 3, seconds = 14, millis = 791;
            TimeSpan timer1lap1 = new TimeSpan(days, hours, minutes, seconds, millis);
            TimeSpan timer1lap2 = new TimeSpan(days, hours, minutes, seconds, millis + 10);
            TimeSpan timer1lap3 = new TimeSpan(days, hours, minutes, seconds + 1, millis);

            TimeSpan timer2lap1 = new TimeSpan(days, hours, minutes, seconds, millis + 10);
            TimeSpan timer2lap2 = new TimeSpan(days, hours, minutes, seconds + 1, millis);
            TimeSpan timer2lap3 = new TimeSpan(days, hours, minutes + 1, seconds, millis);

            _lapTimerManager.AddLapResult(timer1Address, timer1lap1);
            _lapTimerManager.AddLapResult(timer2Address, timer2lap1);
            _lapTimerManager.AddLapResult(timer1Address, timer1lap2);
            _lapTimerManager.AddLapResult(timer2Address, timer2lap2);
            _lapTimerManager.AddLapResult(timer1Address, timer1lap3);
            _lapTimerManager.AddLapResult(timer2Address, timer2lap3);

            LapTimer timer1 = _lapTimerManager.GetLapTimerByIPAddress(timer1Address);

            Assert.NotNull(timer1);
            var timer1AddedLaps = timer1.GetAllLaps();

            Assert.Equal(1, timer1AddedLaps[0].Number);
            Assert.Equal(2, timer1AddedLaps[1].Number);
            Assert.Equal(3, timer1AddedLaps[2].Number);
            Assert.Equal(timer1lap1, timer1AddedLaps[0].Time);
            Assert.Equal(timer1lap2, timer1AddedLaps[1].Time);
            Assert.Equal(timer1lap3, timer1AddedLaps[2].Time);

            LapTimer timer2 = _lapTimerManager.GetLapTimerByIPAddress(timer2Address);

            Assert.NotNull(timer2);
            var timer2AddedLaps = timer2.GetAllLaps();

            Assert.Equal(1, timer2AddedLaps[0].Number);
            Assert.Equal(2, timer2AddedLaps[1].Number);
            Assert.Equal(3, timer2AddedLaps[2].Number);
            Assert.Equal(timer2lap1, timer2AddedLaps[0].Time);
            Assert.Equal(timer2lap2, timer2AddedLaps[1].Time);
            Assert.Equal(timer2lap3, timer2AddedLaps[2].Time);
        }
        public void AddLapResult_OneTimerAndOneResult()
        {
            IPAddress address = IPAddress.Parse("1.1.1.1");

            _lapTimerManager.RegisterLapTimer(address);
            var time = new TimeSpan(0, 1, 20);

            _lapTimerManager.AddLapResult(address, time);

            LapTimer timer = _lapTimerManager.GetLapTimerByIPAddress(address);

            Assert.NotNull(timer);
            var addedLaps = timer.GetAllLaps();

            Assert.Single(addedLaps);
            Assert.Equal(time, addedLaps[0].Time);
        }