public void CheckDuration__DoubleAddressAction_PackingGroup_DurationLessProductOfQuantityByK__AddsPeriodGreaterOperationDuration(int duration, int quantity) { // Arrange: var builder = GetBuilder(); var momento = builder.BuildNew(); var operation = new Operation { Name = "Test Operation", Group = OperationGroups.Packing }; var action = new DoubleAddressAction { StartTime = DateTime.Parse("22.02.2019 8:00:45"), Duration = TimeSpan.FromSeconds(duration), Operation = operation, DoubleAddressDetails = new List <DoubleAddressActionDetail>(new [] { new DoubleAddressActionDetail { ProductQuantity = quantity }, }) }; // Action: builder.CheckDuration(action, momento); // Assert: var res = momento.ProductivityMap[operation].GetTime().TotalSeconds; Assert.That(res, Is.GreaterThan(duration)); }
private static DoubleAddressAction GetDoubleAddressAction(ProductivityImportModel productivityImportModel) { var doubleAction = new DoubleAddressAction { Id = productivityImportModel.DocumentNumber.Trim(), DocumentName = productivityImportModel.DocumentName, StartTime = productivityImportModel.StartTime, Duration = TimeSpan.FromSeconds(productivityImportModel.OperationDuration), Operation = new Operation { Name = productivityImportModel.Operation.Trim() }, Employee = GetEmployee(productivityImportModel), DoubleAddressDetails = new List <DoubleAddressActionDetail> { new DoubleAddressActionDetail { ProductId = productivityImportModel.ProductId ?? 0, Product = GetProduct(productivityImportModel), ProductQuantity = productivityImportModel.ProductQuantity ?? 0, SenderAddress = GetAddress(productivityImportModel.SenderAddress), ReceiverAddress = GetAddress(productivityImportModel.ReceiverAddress) } } }; return(doubleAction); }
public void CheckPause__ThreeNotPacking__SetsExpected() { // in: d4 d4 d4 // |_______________________| // |_______________________| // |______________________| // time: ..12....13....14....15....16....17....18.....19....20....21....22....23....24 // // out: d4 d2 d4 // |_______________________| |____________|______________________| // time: ..12....13....14....15....16....17....18.....19....20....21....22....23....24 // Arrange: var builder = GetBuilder(); var momento = builder.BuildNew(); var operation = new Operation { Name = "Packing Operation", Group = OperationGroups.Gathering }; var action1 = new DoubleAddressAction() { StartTime = DateTime.Parse("22.02.2019 8:12:00"), Duration = TimeSpan.FromMinutes(4), Operation = operation, }; var action2 = new DoubleAddressAction() { StartTime = DateTime.Parse("22.02.2019 8:17:00"), Duration = TimeSpan.FromMinutes(4), Operation = operation, }; var action3 = new DoubleAddressAction() { StartTime = DateTime.Parse("22.02.2019 8:19:00"), Duration = TimeSpan.FromMinutes(4), Operation = operation, }; // Action: var next = builder.CheckDuration(action3, momento); var current = builder.CheckDuration(action2, momento); next = builder.CheckPause(current, next, momento); current = builder.CheckDuration(action1, momento); next = builder.CheckPause(current, next, momento); // Assert: var res = momento; var total = momento.ProductivityMap[operation].GetTime().TotalMinutes; Assert.That(total, Is.EqualTo(10)); Assert.That(momento.DowntimePeriods, Is.Not.Empty); Assert.That(momento.DowntimePeriods.Sum(d => d.Duration.TotalSeconds), Is.EqualTo(40)); }
public void CheckDuration__DoubleAddressAction_OperationIsNull__Throws() { // Arrange: var builder = GetBuilder(); var momento = builder.BuildNew(); var action = new DoubleAddressAction { StartTime = DateTime.Parse("22.02.2019 8:00:45"), Duration = TimeSpan.FromSeconds(20), }; // Action: // Assert: Assert.Catch <ArgumentException>(() => builder.CheckDuration(action, momento)); }
public static TimeSpan GetBuyerGatheringDuration(this DoubleAddressAction action, double bound, int min, int max) { if (action.Operation == null || action.Operation.Group != OperationGroups.BuyerGathering || action.DoubleAddressDetails == null || action.DoubleAddressDetails.Count == 0) { return(action.Duration); } var volume = action.DoubleAddressDetails.Sum(d => d.Volume()); return(volume < bound ? action.Duration + TimeSpan.FromSeconds(min) : action.Duration + TimeSpan.FromSeconds(max)); }
public void CheckPause__CurrentPacking_PackingStartAndEndLessCurrentEnd__SetsCurrentEndEqualToPackingStart() { // curr: |_____________|.. - not paccking -> curr: |_______|..... - not paccking // next: ........|___|..... - packing -> next: ........|___|. - packing // Arrange: var builder = GetBuilder(); var momento = builder.BuildNew(); var gatheringOperation = new Operation { Name = "Current Operation", Group = OperationGroups.Gathering }; var packingOperation = new Operation { Name = "Packing Operation", Group = OperationGroups.Packing }; var currentAction = new InventoryAction { StartTime = DateTime.Parse("22.02.2019 8:00:00"), Duration = TimeSpan.FromSeconds(60), Operation = gatheringOperation, }; var packingAction = new DoubleAddressAction() { StartTime = DateTime.Parse("22.02.2019 8:00:15"), Duration = TimeSpan.FromSeconds(30), Operation = packingOperation, DoubleAddressDetails = new List <DoubleAddressActionDetail>(new [] { new DoubleAddressActionDetail { ProductQuantity = 1 }, }) }; var next = builder.CheckDuration(packingAction, momento); var current = builder.CheckDuration(currentAction, momento); // Action: builder.CheckPause(current, next, momento); // Assert: var res = momento.ProductivityMap[gatheringOperation][currentAction]; Assert.That(res.Duration.TotalSeconds, Is.EqualTo(15)); }
public void SubstractBreaks_ActionBreakGreaterBreakTime_DowntimesNotEmptyInResult(string st0, int dur0, string st1) { // Arrange: var builder = GetBuilder(); var momento = builder.BuildNew(); var operation = new Operation { Name = "Packing Operation", Group = OperationGroups.Gathering }; var shortBreaks = new ShortBreakSchedule { Duration = TimeSpan.FromMinutes(5), FirstBreakTime = new TimeSpan(8, 55, 0), Periodicity = TimeSpan.FromHours(1) }; var actions = new DoubleAddressAction[] { new DoubleAddressAction() { StartTime = DateTime.Parse(st0), Duration = TimeSpan.FromMinutes(dur0), Operation = operation, }, new DoubleAddressAction() { StartTime = DateTime.Parse(st1), Duration = TimeSpan.FromMinutes(55), Operation = operation, }, }; // Action: var next = builder.CheckDuration(actions[1], momento); var current = builder.CheckDuration(actions[0], momento); builder.CheckPause(current, next, momento); builder.SubstractBreaks(shortBreaks, momento); // Assert: Assert.That(momento.DowntimePeriods, Is.Not.Empty); }
public static TimeSpan GetPackingDuration(this DoubleAddressAction action, double[] koefs) { if (action.Operation == null || action.Operation.Group != OperationGroups.Packing || action.DoubleAddressDetails == null || action.DoubleAddressDetails.Count == 0 || koefs == null || koefs.Length < 4) { return(action.Duration); } var quantity = action.DoubleAddressDetails.Sum(d => d.ProductQuantity); var dur = action.Duration.TotalSeconds; if (quantity < 10) { return(GetDuration(0)); } if (quantity < 20) { return(GetDuration(1)); } if (quantity < 30) { return(GetDuration(2)); } return(GetDuration(3)); TimeSpan GetDuration(int i) { var s = 0; checked { s = (int)Math.Floor(quantity * koefs[i]); } return(dur < s ? TimeSpan.FromSeconds(s) : action.Duration); } }
public void CheckDuration__DoubleAddressAction_GatheringGroup__AddsNotZeroPeriodToDictionary() { // Arrange: var builder = GetBuilder(); var momento = builder.BuildNew(); var operation = new Operation { Name = "Test Operation", Group = OperationGroups.Gathering }; var action = new DoubleAddressAction { StartTime = DateTime.Parse("22.02.2019 8:00:45"), Duration = TimeSpan.FromSeconds(20), Operation = operation }; // Action: builder.CheckDuration(action, momento); // Assert: var res = momento.ProductivityMap[operation].GetTime(); Assert.That(res, Is.Not.EqualTo(Period.Zero)); }
public void CheckDuration__DoubleAddressAction_PackingGroup_DetailsIsNull__AddsPeriodEqualsDuration() { // Arrange: var builder = GetBuilder(); var momento = builder.BuildNew(); var operation = new Operation { Name = "Test Operation", Group = OperationGroups.Packing }; int duration = 10; var action = new DoubleAddressAction { StartTime = DateTime.Parse("22.02.2019 8:00:45"), Duration = TimeSpan.FromSeconds(duration), Operation = operation, }; // Action: builder.CheckDuration(action, momento); // Assert: var res = momento.ProductivityMap[operation].GetTime().TotalSeconds; Assert.That(res, Is.EqualTo(duration)); }
public void CheckDuration__DoubleAddressAction_BuyerGatheringGroup_VolumeGreater5__AddsPeriodGreaterBy60Sec() { // Arrange: var builder = GetBuilder(); var momento = builder.BuildNew(); var operation = new Operation { Name = "Test Operation", Group = OperationGroups.BuyerGathering }; var duration = 1; var action = new DoubleAddressAction { StartTime = DateTime.Parse("22.02.2019 8:00:45"), Duration = TimeSpan.FromSeconds(duration), Operation = operation, DoubleAddressDetails = new List <DoubleAddressActionDetail>(new [] { new DoubleAddressActionDetail { ProductQuantity = 1, Product = new Product { ItemVolume = 11 } }, new DoubleAddressActionDetail { ProductQuantity = 1, Product = new Product { ItemVolume = 3 } }, }) }; // Action: builder.CheckDuration(action, momento); // Assert: var res = momento.ProductivityMap[operation].GetTime().TotalSeconds; Assert.That(res, Is.EqualTo(duration + 60)); }