public void TrainSegmentModelClassSplitAtIndexMethodReturnsNullIfParameterIsEqualToTimingsPropertyCountProperty() { TrainSegmentModel testObject = GetTestObject(null, null, null, null); TrainSegmentModel testOutput = testObject.SplitAtIndex(testObject.Timings.Count, _rnd.Next()); Assert.IsNull(testOutput); }
public void TrainSegmentModelClassSplitAtIndexMethodReturnsNullIfParameterIsSameAsIndexOfLastTimingEntry() { TrainSegmentModel testObject = GetTestObject(null, null, null, null); TrainSegmentModel testOutput = testObject.SplitAtIndex(testObject.Timings.Count - 1, _rnd.Next()); Assert.IsNull(testOutput); }
public void TrainSegmentModelClassSplitAtIndexMethodReturnsNullIfParameterIsZero() { TrainSegmentModel testObject = GetTestObject(null, null, null, null); TrainSegmentModel testOutput = testObject.SplitAtIndex(0, _rnd.Next()); Assert.IsNull(testOutput); }
public void TrainSegmentModelClassSplitAtIndexMethodReturnsNonNullResultIfParameterIsGreaterThanZeroAndLessThanFinalIndexOfTimingsProperty() { TrainSegmentModel testObject = GetTestObject(null, null, null, null); int testParam0 = _rnd.Next(testObject.Timings.Count - 2) + 1; TrainSegmentModel testOutput = testObject.SplitAtIndex(testParam0, _rnd.Next()); Assert.IsNotNull(testOutput); }
public void TrainSegmentModelClassSplitAtIndexMethodReturnsNullIfParameterIsEqualToOrGreaterThanTimingsPropertyCountProperty() { TrainSegmentModel testObject = GetTestObject(null, null, null, null); int testParam0 = _rnd.Next(int.MaxValue - testObject.Timings.Count) + testObject.Timings.Count; TrainSegmentModel testOutput = testObject.SplitAtIndex(testParam0, _rnd.Next()); Assert.IsNull(testOutput); }
public void TrainSegmentModelClassSplitAtIndexMethodReturnsObjectWithCorrectTrainIdProperty() { TrainSegmentModel testObject = GetTestObject(null, null, null, null); int testParam0 = _rnd.Next(testObject.Timings.Count - 2) + 1; int testParam1 = _rnd.Next(testObject.Timings.Count - testParam0); TrainSegmentModel testOutput = testObject.SplitAtIndex(testParam0, testParam1); Assert.AreEqual(testObject.TrainId, testOutput.TrainId); }
public void TrainSegmentModelClassSplitAtIndexMethodSetsInlineNotePropertyOfParameterToEmptyString() { TrainSegmentModel testObject = GetTestObject(null, null, null, null); int testParam0 = _rnd.Next(testObject.Timings.Count - 2) + 1; int testParam1 = _rnd.Next(testObject.Timings.Count - testParam0); _ = testObject.SplitAtIndex(testParam0, testParam1); Assert.AreEqual("", testObject.InlineNote); }
public void TrainSegmentModelClassSplitAtIndexMethodSetsContinuesLaterPropertyOfOriginalSegmentToTrue() { TrainSegmentModel testObject = GetTestObject(null, null, false, null); int testParam0 = _rnd.Next(testObject.Timings.Count - 2) + 1; int testParam1 = _rnd.Next(testObject.Timings.Count - testParam0); _ = testObject.SplitAtIndex(testParam0, testParam1); Assert.IsTrue(testObject.ContinuesLater); }
public void TrainSegmentModelClassSplitAtIndexMethodReturnsNullIfParameterIsLessThanZero() { int testParam0 = _rnd.Next(int.MaxValue - 1) * -1 - 1; int testParam1 = _rnd.Next(); TrainSegmentModel testObject = GetTestObject(null, null, null, null); TrainSegmentModel testOutput = testObject.SplitAtIndex(testParam0, testParam1); Assert.IsNull(testOutput); }
public void TrainSegmentModelClassSplitAtIndexMethodReturnsObjectWithPageFootnotesPropertyOfCorrectLength() { TrainSegmentModel testObject = GetTestObject(null, null, null, null); int testParam0 = _rnd.Next(testObject.Timings.Count - 2) + 1; int testParam1 = _rnd.Next(testObject.Timings.Count - testParam0); TrainSegmentModel testOutput = testObject.SplitAtIndex(testParam0, testParam1); Assert.AreEqual(testObject.PageFootnotes.Count, testOutput.PageFootnotes.Count); }
public void TrainSegmentModelClassSplitAtIndexMethodReturnsObjectWithContinuationFromEarlierPropertyEqualToTrue() { TrainSegmentModel testObject = GetTestObject(null, null, null, null); int testParam0 = _rnd.Next(testObject.Timings.Count - 2) + 1; int testParam1 = _rnd.Next(testObject.Timings.Count - testParam0); TrainSegmentModel testOutput = testObject.SplitAtIndex(testParam0, testParam1); Assert.IsTrue(testOutput.ContinuationFromEarlier); }
public void TrainSegmentModelClassSplitAtIndexMethodReducesNumberOfTimingsInOriginalSegmentToSplitPointPlusOverlap() { TrainSegmentModel testObject = GetTestObject(null, null, null, null); int testParam0 = _rnd.Next(testObject.Timings.Count - 2) + 1; int testParam1 = _rnd.Next(testObject.Timings.Count - testParam0); _ = testObject.SplitAtIndex(testParam0, testParam1); Assert.AreEqual(testParam0 + testParam1, testObject.Timings.Count); }
public void TrainSegmentModelClassSplitAtIndexMethodReturnsObjectWithCorrectContinuesLaterProperty() { TrainSegmentModel testObject = GetTestObject(null, null, null, null); int testParam0 = _rnd.Next(testObject.Timings.Count - 2) + 1; int testParam1 = _rnd.Next(testObject.Timings.Count - testParam0); bool originalContinuesLater = testObject.ContinuesLater; TrainSegmentModel testOutput = testObject.SplitAtIndex(testParam0, testParam1); Assert.AreEqual(originalContinuesLater, testOutput.ContinuesLater); }
public void TrainSegmentModelClassSplitAtIndexMethodReducesNumberOfTimingsInOriginalSegmentIfSplitPointPlusOverlapIsLessThanTotalNumberOfTimings() { TrainSegmentModel testObject = GetTestObject(null, null, null, null); int testParam0 = _rnd.Next(testObject.Timings.Count - 2) + 1; int testParam1 = _rnd.Next(testObject.Timings.Count - testParam0); int timingCount = testObject.Timings.Count; _ = testObject.SplitAtIndex(testParam0, testParam1); Assert.IsTrue(testObject.Timings.Count < timingCount); }
public void TrainSegmentModelClassSplitAtIndexMethodDoesNotReduceNumberOfTimingsInOriginalSegmentIfOverlapIsGreaterThanNumberOfTimingsBetweenSplitPointAndEnd() { TrainSegmentModel testObject = GetTestObject(null, null, null, null); int testParam0 = _rnd.Next(testObject.Timings.Count - 2) + 1; int testParam1 = _rnd.Next(int.MaxValue - testObject.Timings.Count) + testObject.Timings.Count - testParam0; int timingCount = testObject.Timings.Count; _ = testObject.SplitAtIndex(testParam0, testParam1); Assert.AreEqual(timingCount, testObject.Timings.Count); }
public void TrainSegmentModelClassSplitAtIndexMethodReturnsObjectWithCorrectNumberOfTimings() { // The correct number of timings is: the number of elements from the split point to the end. TrainSegmentModel testObject = GetTestObject(null, null, null, null); int testParam0 = _rnd.Next(testObject.Timings.Count - 2) + 1; int testParam1 = _rnd.Next(testObject.Timings.Count - testParam0); List <ILocationEntry> savedTimings = testObject.Timings.Select(t => t.Copy()).ToList(); TrainSegmentModel testOutput = testObject.SplitAtIndex(testParam0, testParam1); Assert.AreEqual(savedTimings.Count - testParam0, testOutput.Timings.Count); }
public void TrainSegmentModelClassSplitAtIndexMethodReturnsObjectWithPageFootnotesPropertyContainingObjectsWithCorrectDisplayOnPageProperty() { TrainSegmentModel testObject = GetTestObject(null, null, null, null); int testParam0 = _rnd.Next(testObject.Timings.Count - 2) + 1; int testParam1 = _rnd.Next(testObject.Timings.Count - testParam0); TrainSegmentModel testOutput = testObject.SplitAtIndex(testParam0, testParam1); for (int i = 0; i < testOutput.PageFootnotes.Count; ++i) { Assert.AreEqual(testObject.PageFootnotes[i].DisplayOnPage, testOutput.PageFootnotes[i].DisplayOnPage); } }
public void TrainSegmentModelClassSplitAtIndexMethodKeepsCorrectTimingsInOriginalSegment() { TrainSegmentModel testObject = GetTestObject(null, null, null, null); int testParam0 = _rnd.Next(testObject.Timings.Count - 2) + 1; int testParam1 = _rnd.Next(testObject.Timings.Count - testParam0); List <ILocationEntry> savedTimings = testObject.Timings.Select(t => t.Copy()).ToList(); TrainSegmentModel testOutput = testObject.SplitAtIndex(testParam0, testParam1); for (int i = 0; i < testObject.Timings.Count; ++i) { Assert.AreEqual(savedTimings[i].LocationKey, testObject.Timings[i].LocationKey); } }
public void TrainSegmentModelClassSplitAtIndexMethodReturnsObjectWithTimingsPropertyWithObjectsContainingCorrectLocationKeys() { TrainSegmentModel testObject = GetTestObject(null, null, null, null); int testParam0 = _rnd.Next(testObject.Timings.Count - 2) + 1; int testParam1 = _rnd.Next(testObject.Timings.Count - testParam0); List <ILocationEntry> savedTimings = testObject.Timings.Select(t => t.Copy()).ToList(); TrainSegmentModel testOutput = testObject.SplitAtIndex(testParam0, testParam1); for (int i = 0; i < testOutput.Timings.Count; ++i) { Assert.AreEqual(savedTimings[i + testParam0].LocationKey, testOutput.Timings[i].LocationKey); } }
public void TrainSegmentModelClassSplitAtIndexMethodReturnsObjectWithCorrectHalfOfDayPropertyIfSplitIsAfterMidday() { TrainSegmentModel testObject = GetTestObject(0, null, null, null, new List <ILocationEntry> { new TrainLocationTimeModel { LocationKey = "A", ActualTime = new TimeOfDay(11, 0) }, new TrainLocationTimeModel { LocationKey = "B", ActualTime = new TimeOfDay(11, 30) }, new TrainLocationTimeModel { LocationKey = "C", ActualTime = new TimeOfDay(12, 10) }, new TrainLocationTimeModel { LocationKey = "D", ActualTime = new TimeOfDay(12, 15) }, }); TrainSegmentModel testOutput = testObject.SplitAtIndex(2, 1); Assert.AreEqual("P.M.", testOutput.HalfOfDay); }
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)); }