public void IndexedTrainLocationTimeModelClassModelPropertyIsNullIfEntryPropertyIsNull()
        {
            IndexedTrainLocationTimeModel testObject = new IndexedTrainLocationTimeModel {
                Entry = null
            };

            TrainLocationTimeModel testOutput = testObject.Model;

            Assert.IsNull(testOutput);
        }
        public void IndexedTrainLocationTimeModelClassModelPropertyReturnsSameObjectAsEntryPropertyIfTypeOfObjectIsTrainLocationTimeModel()
        {
            IndexedTrainLocationTimeModel testObject = new IndexedTrainLocationTimeModel {
                Entry = new TrainLocationTimeModel()
            };

            TrainLocationTimeModel testOutput = testObject.Model;

            Assert.AreSame(testObject.Entry, testOutput);
        }
Exemple #3
0
        private static Tuple <int, TrainSegmentModel> CompareWithSharedTimes(TrainSegmentModel x, TrainSegmentModel y)
        {
            // Check first common time
            var xFirstCommon = x.Timings.First(t => t is TrainLocationTimeModel && y.TimingsIndex.ContainsKey(t.LocationKey)) as TrainLocationTimeModel;
            var XCommonTimes = x.Timings
                               .Select((t, i) => new IndexedTrainLocationTimeModel {
                Entry = t, Index = i
            })
                               .Where(t => t.Model != null && y.TimingsIndex.ContainsKey(t.Model.LocationKey))
                               .ToList();
            List <int> timeComparisons = new List <int>(XCommonTimes.Count);
            List <IndexedTrainLocationTimeModel> YCommonTimes = new List <IndexedTrainLocationTimeModel>();

            foreach (IndexedTrainLocationTimeModel entry in XCommonTimes)
            {
                ILocationEntry yEntry = y.TimingsIndex[entry.Entry.LocationKey];
                var            yModel = new IndexedTrainLocationTimeModel {
                    Entry = yEntry, Index = y.Timings.IndexOf(yEntry)
                };
                YCommonTimes.Add(yModel);
                if (!(x.ContinuationFromEarlier && entry.Index == 0) && !(y.ContinuationFromEarlier && yModel.Index == 0) && !(x.ContinuesLater && entry.Index == x.Timings.Count - 1) &&
                    !(y.ContinuesLater && yModel.Index == y.Timings.Count - 1))
                {
                    timeComparisons.Add(GenericTimeModelComparer.Default.Compare(entry.Model, yModel.Model));
                }
            }

            if (timeComparisons.All(t => t == 0))
            {
                return(new Tuple <int, TrainSegmentModel>(0, null));
            }

            List <int> differentTimeComparisons = timeComparisons.Where(t => t != 0).ToList();
            int        firstDifference          = differentTimeComparisons[0];

            if (differentTimeComparisons.Skip(1).All(t => t == firstDifference))
            {
                return(new Tuple <int, TrainSegmentModel>(firstDifference, null));
            }

            int switchIdx = 0;

            foreach (int tc in timeComparisons.Skip(1))
            {
                if (tc != firstDifference && tc != 0)
                {
                    break;
                }
                switchIdx++;
            }

            TrainSegmentModel splitSegment;

            if (firstDifference < 0)
            {
                splitSegment = x.SplitAtIndex(XCommonTimes[switchIdx].Index, 2);
            }
            else
            {
                splitSegment = y.SplitAtIndex(YCommonTimes[switchIdx].Index, 2);
            }
            return(new Tuple <int, TrainSegmentModel>(firstDifference, splitSegment));
        }