Exemplo n.º 1
0
        public void CalculationBLLTest_GetFollowUpService_WrongDay()
        {
            var estw = new ESTW("ID", "Name", string.Empty, null);

            estw.Time = new LeibitTime(eDaysOfService.Saturday, 14, 45);

            var train = new Train(1);

            new Schedule(train, new LeibitTime(14, 56), null, null, new List <eDaysOfService>(), eScheduleDirection.Unknown, eHandling.Destination, string.Empty);

            var relation = new TrainRelation(2);

            relation.Days.Add(eDaysOfService.Monday);
            relation.Days.Add(eDaysOfService.Tuesday);
            relation.Days.Add(eDaysOfService.Wednesday);
            relation.Days.Add(eDaysOfService.Thursday);
            relation.Days.Add(eDaysOfService.Friday);
            train.FollowUpServices.Add(relation);

            var bll    = new CalculationBLL();
            var result = bll.GetFollowUpService(train, estw);

            Assert.IsTrue(result.Succeeded);
            Assert.IsNull(result.Result);
        }
Exemplo n.º 2
0
        public void CalculationBLLTest_GetPreviousService_SimpleCase()
        {
            var estw  = new ESTW("ID", "Name", string.Empty, null);
            var train = new Train(1);

            var relation = new TrainRelation(2);

            relation.Days.Add(eDaysOfService.Monday);
            relation.Days.Add(eDaysOfService.Tuesday);
            relation.Days.Add(eDaysOfService.Wednesday);
            relation.Days.Add(eDaysOfService.Thursday);
            relation.Days.Add(eDaysOfService.Friday);
            relation.Days.Add(eDaysOfService.Saturday);
            relation.Days.Add(eDaysOfService.Sunday);
            train.PreviousServices.Add(relation);

            var bll    = new CalculationBLL();
            var result = bll.GetPreviousService(train, estw);

            Assert.IsTrue(result.Succeeded);
            Assert.AreEqual(2, result.Result);
        }
Exemplo n.º 3
0
        public void CalculationBLLTest_GetFollowUpService_BeforeMidnight()
        {
            var estw = new ESTW("ID", "Name", string.Empty, null);

            estw.Time = new LeibitTime(eDaysOfService.Thursday, 23, 55);

            var train = new Train(0);

            new Schedule(train, new LeibitTime(0, 5), null, null, new List <eDaysOfService>(), eScheduleDirection.Unknown, eHandling.Destination, string.Empty);

            var relation = new TrainRelation(1);

            relation.Days.Add(eDaysOfService.Monday);
            train.FollowUpServices.Add(relation);

            relation = new TrainRelation(2);
            relation.Days.Add(eDaysOfService.Tuesday);
            train.FollowUpServices.Add(relation);

            relation = new TrainRelation(3);
            relation.Days.Add(eDaysOfService.Wednesday);
            train.FollowUpServices.Add(relation);

            relation = new TrainRelation(4);
            relation.Days.Add(eDaysOfService.Thursday);
            train.FollowUpServices.Add(relation);

            relation = new TrainRelation(5);
            relation.Days.Add(eDaysOfService.Friday);
            train.FollowUpServices.Add(relation);

            var bll    = new CalculationBLL();
            var result = bll.GetFollowUpService(train, estw);

            Assert.IsTrue(result.Succeeded);
            Assert.AreEqual(5, result.Result);
        }
Exemplo n.º 4
0
        public void CalculationBLLTest_GetPreviousService_BeforeMidnight()
        {
            var area = new Area("ID", "Name");
            var estw = new ESTW("ID", "Name", string.Empty, area);

            estw.Time = new LeibitTime(eDaysOfService.Thursday, 23, 45);

            var train = new Train(0);

            var train1 = new Train(1);

            new Schedule(train1, new LeibitTime(0, 55), null, null, new List <eDaysOfService>(), eScheduleDirection.Unknown, eHandling.Destination, string.Empty);
            area.Trains.TryAdd(1, train1);

            var train2 = new Train(2);

            new Schedule(train2, new LeibitTime(0, 55), null, null, new List <eDaysOfService>(), eScheduleDirection.Unknown, eHandling.Destination, string.Empty);
            area.Trains.TryAdd(2, train2);

            var train3 = new Train(3);

            new Schedule(train3, new LeibitTime(0, 55), null, null, new List <eDaysOfService>(), eScheduleDirection.Unknown, eHandling.Destination, string.Empty);
            area.Trains.TryAdd(3, train3);

            var train4 = new Train(4);

            new Schedule(train4, new LeibitTime(0, 55), null, null, new List <eDaysOfService>(), eScheduleDirection.Unknown, eHandling.Destination, string.Empty);
            area.Trains.TryAdd(4, train4);

            var train5 = new Train(5);

            new Schedule(train5, new LeibitTime(0, 55), null, null, new List <eDaysOfService>(), eScheduleDirection.Unknown, eHandling.Destination, string.Empty);
            area.Trains.TryAdd(5, train5);

            var relation = new TrainRelation(1);

            relation.Days.Add(eDaysOfService.Monday);
            train.PreviousServices.Add(relation);

            relation = new TrainRelation(2);
            relation.Days.Add(eDaysOfService.Tuesday);
            train.PreviousServices.Add(relation);

            relation = new TrainRelation(3);
            relation.Days.Add(eDaysOfService.Wednesday);
            train.PreviousServices.Add(relation);

            relation = new TrainRelation(4);
            relation.Days.Add(eDaysOfService.Thursday);
            train.PreviousServices.Add(relation);

            relation = new TrainRelation(5);
            relation.Days.Add(eDaysOfService.Friday);
            train.PreviousServices.Add(relation);

            var bll    = new CalculationBLL();
            var result = bll.GetPreviousService(train, estw);

            Assert.IsTrue(result.Succeeded);
            Assert.AreEqual(5, result.Result);
        }
Exemplo n.º 5
0
        private void __LoadTrainRelations(ESTW estw, string path)
        {
            var routingFilesPath = Path.Combine(path, Constants.TRAIN_ROUTING_FOLDER);

            if (!Directory.Exists(routingFilesPath))
            {
                return;
            }

            foreach (var file in Directory.EnumerateFiles(routingFilesPath, "*.znu"))
            {
                using (var fileReader = File.OpenText(file))
                {
                    while (!fileReader.EndOfStream)
                    {
                        var line  = fileReader.ReadLine();
                        var parts = line.Split(' ');

                        if (parts.Length < 2)
                        {
                            continue;
                        }

                        var    sFromTrainNumber = parts[0];
                        var    sToTrainNumber = parts[1];
                        string sFromDay, sToDay;

                        if (parts.Length >= 4)
                        {
                            sFromDay = parts[2];
                            sToDay   = parts[3];
                        }
                        else
                        {
                            sFromDay = "1"; // Monday
                            sToDay   = "7"; // Sunday
                        }

                        if (!int.TryParse(sFromTrainNumber, out var fromTrainNumber) ||
                            !int.TryParse(sToTrainNumber, out var toTrainNumber) ||
                            !estw.Area.Trains.ContainsKey(fromTrainNumber) ||
                            !estw.Area.Trains.ContainsKey(toTrainNumber) ||
                            !LeibitTime.TryParseSingleDay(sFromDay, out var fromDay) ||
                            !LeibitTime.TryParseSingleDay(sToDay, out var toDay))
                        {
                            continue;
                        }

                        var daysOfService = new List <eDaysOfService>();

                        for (int i = (int)fromDay; i != (int)toDay;)
                        {
                            daysOfService.Add((eDaysOfService)i);

                            i *= 2;

                            if (i > 64)
                            {
                                i = 1;
                            }
                        }

                        daysOfService.Add(toDay);

                        var fromTrain = estw.Area.Trains[fromTrainNumber];
                        var toTrain   = estw.Area.Trains[toTrainNumber];

                        var trainRelation = new TrainRelation(toTrainNumber);
                        trainRelation.Days.AddRange(daysOfService);
                        fromTrain.FollowUpServices.Add(trainRelation);

                        trainRelation = new TrainRelation(fromTrainNumber);
                        trainRelation.Days.AddRange(daysOfService);
                        toTrain.PreviousServices.Add(trainRelation);
                    }
                }
            }
        }