コード例 #1
0
        public void RaceInformationTest()
        {
            //Arrange
            var extractService = new ExtractDataFake();
            var computeService = new ComputeRankingKartRaceService();
            var outputService  = new OutputKartRaceInformationService();

            //Act
            KartRaceInformation raceInfo = new KartRaceInformation(extractService, computeService, outputService);

            raceInfo.ExtractDataFromFile("bazinga.txt");
            raceInfo.ComputeRanking();
            raceInfo.GetBestLap();
            raceInfo.PrintOutput();

            //Assert
            Assert.AreEqual(raceInfo.Laps.Count, 4);
            Assert.AreEqual(raceInfo.Ranking.Count, 2);

            Assert.AreEqual(raceInfo.Ranking[0].PilotCode, "001");
            Assert.AreEqual(raceInfo.Ranking[0].PilotName, "Pilot 1");
            Assert.AreEqual(raceInfo.Ranking[0].BestLapNumber, 2);

            Assert.AreEqual(raceInfo.Ranking[1].PilotCode, "002");
            Assert.AreEqual(raceInfo.Ranking[1].PilotName, "Pilot 2");
            Assert.AreEqual(raceInfo.Ranking[1].BestLapNumber, 1);

            Assert.AreEqual(raceInfo.BestLap.PilotCode, "001");
            Assert.AreEqual(raceInfo.BestLap.PilotName, "Pilot 1");
            Assert.AreEqual(raceInfo.BestLap.BestLapNumber, 2);
        }
        public void GetBestLapByFirstPilot()
        {
            //Arrange
            ComputeRankingKartRaceService computeService = new ComputeRankingKartRaceService();

            List <KartLap> kartLaps = new List <KartLap>();

            kartLaps.Add(new KartLap()
            {
                PilotCode       = "001",
                PilotName       = "Pilot 1",
                LapNumber       = 1,
                Time            = new TimeSpan(0, 1, 1, 1, 1234),
                LapTime         = new TimeSpan(0, 1, 1, 1, 1234),
                LapAverageSpeed = 10
            });

            kartLaps.Add(new KartLap()
            {
                PilotCode       = "002",
                PilotName       = "Pilot 2",
                LapNumber       = 1,
                Time            = new TimeSpan(0, 1, 1, 1, 1222),
                LapTime         = new TimeSpan(0, 1, 1, 1, 1222),
                LapAverageSpeed = 10
            });

            kartLaps.Add(new KartLap()
            {
                PilotCode       = "001",
                PilotName       = "Pilot 1",
                LapNumber       = 2,
                Time            = new TimeSpan(0, 1, 1, 1, 1220),
                LapTime         = new TimeSpan(0, 1, 1, 1, 1220),
                LapAverageSpeed = 10
            });

            kartLaps.Add(new KartLap()
            {
                PilotCode       = "002",
                PilotName       = "Pilot 2",
                LapNumber       = 2,
                Time            = new TimeSpan(0, 1, 1, 1, 1233),
                LapTime         = new TimeSpan(0, 1, 1, 1, 1233),
                LapAverageSpeed = 10
            });

            //Act
            computeService.ComputeRanking(kartLaps);
            KartRaceResult result = computeService.GetBestLap();

            //Assert
            Assert.AreEqual(result.PilotCode, "001");
            Assert.AreEqual(result.PilotName, "Pilot 1");
            Assert.AreEqual(result.BestLapNumber, 2);
        }
コード例 #3
0
        static void Main(string[] args)
        {
            var dataParser = new DataExtractedParser();
            var positionalExtractorService = new PositionalDataLineExtrator <KartLap>(dataParser);

            var extractService = new ExtractKartRaceFileService(positionalExtractorService);
            var computeService = new ComputeRankingKartRaceService();
            var outputService  = new OutputKartRaceInformationService();

            KartRaceInformation raceInfo = new KartRaceInformation(extractService, computeService, outputService);

            raceInfo.ExtractDataFromFile("data.txt");
            raceInfo.ComputeRanking();
            raceInfo.GetBestLap();
            raceInfo.PrintOutput();

            Console.WriteLine("\nPress any key to exit");
            Console.ReadKey();
        }
        public void RankingLapsBySecondPilot()
        {
            //Arrange
            ComputeRankingKartRaceService computeService = new ComputeRankingKartRaceService();

            List <KartLap> kartLaps = new List <KartLap>();

            kartLaps.Add(new KartLap()
            {
                PilotCode       = "001",
                PilotName       = "Pilot 1",
                LapNumber       = 1,
                Time            = new TimeSpan(0, 1, 1, 1, 1234),
                LapTime         = new TimeSpan(0, 1, 1, 1, 1234),
                LapAverageSpeed = 10
            });

            kartLaps.Add(new KartLap()
            {
                PilotCode       = "002",
                PilotName       = "Pilot 2",
                LapNumber       = 1,
                Time            = new TimeSpan(0, 1, 1, 1, 1222),
                LapTime         = new TimeSpan(0, 1, 1, 1, 1222),
                LapAverageSpeed = 10
            });

            kartLaps.Add(new KartLap()
            {
                PilotCode       = "001",
                PilotName       = "Pilot 1",
                LapNumber       = 2,
                Time            = new TimeSpan(0, 1, 1, 1, 1223),
                LapTime         = new TimeSpan(0, 1, 1, 1, 1223),
                LapAverageSpeed = 10
            });

            kartLaps.Add(new KartLap()
            {
                PilotCode       = "002",
                PilotName       = "Pilot 2",
                LapNumber       = 2,
                Time            = new TimeSpan(0, 1, 1, 1, 1233),
                LapTime         = new TimeSpan(0, 1, 1, 1, 1233),
                LapAverageSpeed = 10
            });

            //Act
            List <KartRaceResult> result = computeService.ComputeRanking(kartLaps);

            //Assert
            Assert.AreEqual(result.Count, 2);

            Assert.AreEqual(result[0].PilotCode, "002");
            Assert.AreEqual(result[0].PilotName, "Pilot 2");
            Assert.AreEqual(result[0].BestLapNumber, 1);

            Assert.AreEqual(result[1].PilotCode, "001");
            Assert.AreEqual(result[1].PilotName, "Pilot 1");
            Assert.AreEqual(result[1].BestLapNumber, 2);
        }