本文整理汇总了C#中Collection.TryToMakeTasksComply方法的典型用法代码示例。如果您正苦于以下问题:C# Collection.TryToMakeTasksComply方法的具体用法?C# Collection.TryToMakeTasksComply怎么用?C# Collection.TryToMakeTasksComply使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Collection
的用法示例。
在下文中一共展示了Collection.TryToMakeTasksComply方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryToMakeTasksComply_WillGoBelowMinValue_ReturnsCorrectCollection
public void TryToMakeTasksComply_WillGoBelowMinValue_ReturnsCorrectCollection()
{
// Arrange
double minLevel = 100;
double maxLevel = 200;
double initialLevel = 100;
var taskCollection = new Collection<ITask>();
DateTime t1 = DateTime.Now;
DateTime t2 = t1.AddHours(1);
DateTime t3 = t1.AddHours(2);
DateTime t4 = t1.AddHours(3);
Task task1 = Task.CreateUsingQuantity(t1, t2,-100);
Task task2 = Task.CreateUsingQuantity(t3, t4, 100);
taskCollection.Add(task1);
taskCollection.Add(task2);
// Act
IEnumerable<ITask> newCollection = taskCollection.TryToMakeTasksComply(minLevel, maxLevel, initialLevel);
// Assert
var correctCollection = new Collection<ITask>();
correctCollection.Add(task1.ChangeTimes(t3)); // The consuming task moves forward
correctCollection.Add(task2);
Assert.AreEqual(correctCollection, newCollection);
Assert.True(newCollection.WillStayWithinRange(minLevel, maxLevel, initialLevel));
}
示例2: TryToMakeTasksComply_WillGoBelowMinValue_ReturnsCorrectCollection2
public void TryToMakeTasksComply_WillGoBelowMinValue_ReturnsCorrectCollection2()
{
// Arrange
double minLevel = 100;
double maxLevel = 200;
double initialLevel = 100;
var taskCollection = new Collection<ITask>();
DateTime t1 = DateTime.Now;
DateTime t2 = t1.AddHours(1);
DateTime t3 = t1.AddHours(2);
DateTime t4 = t1.AddHours(3);
Task task1 = Task.CreateUsingQuantity(t1, t2, -100);
Task task2 = Task.CreateUsingQuantity(t2, t3, 50);
Task task3 = Task.CreateUsingQuantity(t3, t4, 30);
Task task4 = Task.CreateUsingQuantity(t2, t4, 20);
taskCollection.Add(task1);
taskCollection.Add(task2);
taskCollection.Add(task3);
taskCollection.Add(task4);
// Act
IEnumerable<ITask> newCollection = taskCollection.TryToMakeTasksComply(minLevel, maxLevel, initialLevel);
// Assert
var producingTasks = newCollection.OrderBy(x => x.DateInterval).Where(task => task.TaskType == TaskType.Produce).ToList();
Assert.AreEqual(t4, newCollection.Single(task => task.TaskType == TaskType.Consume).EndTime);
Assert.AreEqual(task1.Duration, newCollection.Single(task => task.TaskType == TaskType.Consume).Duration);
Assert.True(producingTasks[0].Equals(task2));
Assert.True(producingTasks[1].Equals(task4));
Assert.True(producingTasks[2].Equals(task3));
Assert.True(newCollection.WillStayWithinRange(minLevel, maxLevel, initialLevel));
}
示例3: TryToMakeTasksComply_WillGoAboveMaxValue_ReturnsCorrectCollection2
public void TryToMakeTasksComply_WillGoAboveMaxValue_ReturnsCorrectCollection2()
{
// Arrange
double minLevel = 100;
double maxLevel = 200;
double initialLevel = 200;
var taskCollection = new Collection<ITask>();
DateTime t1 = DateTime.Now;
DateTime t2 = t1.AddHours(1);
DateTime t3 = t1.AddHours(2);
DateTime t4 = t1.AddHours(3);
Task task1 = Task.CreateUsingQuantity(t1, t2, 100);
Task task2 = Task.CreateUsingQuantity(t2, t3, -50);
Task task3 = Task.CreateUsingQuantity(t3, t4, -30);
Task task4 = Task.CreateUsingQuantity(t2, t4, -20);
taskCollection.Add(task1);
taskCollection.Add(task2);
taskCollection.Add(task3);
taskCollection.Add(task4);
// Act
IEnumerable<ITask> newCollection = taskCollection.TryToMakeTasksComply(minLevel, maxLevel, initialLevel);
// Assert
var consumingTasks = newCollection.OrderBy(x => x.DateInterval).Where(task => task.TaskType == TaskType.Consume).ToList();
Assert.AreEqual(t4, newCollection.Single(task => task.TaskType == TaskType.Produce).EndTime); // Don't move producing task forward more than you need to.
Assert.AreEqual(task1.Duration, newCollection.Single(task => task.TaskType == TaskType.Produce).Duration);
// Consuming tasks do not change. Only the producing tasks change since the level went over the max value.
Assert.True(consumingTasks[0].Equals( task2 ));
Assert.True(consumingTasks[1].Equals( task4 ));
Assert.True(consumingTasks[2].Equals( task3 ));
Assert.True(newCollection.WillStayWithinRange(minLevel, maxLevel, initialLevel));
}
示例4: TryToMakeTasksComply_WillGoAboveMaxValue_ReturnsCorrectCollection3
public void TryToMakeTasksComply_WillGoAboveMaxValue_ReturnsCorrectCollection3()
{
// Arrange
double minLevel = 100;
double maxLevel = 200;
double initialLevel = 170;
var taskCollection = new Collection<ITask>();
DateTime t1 = DateTime.Now;
DateTime t2 = t1.AddHours(1);
DateTime t3 = t1.AddHours(2);
DateTime t4 = t1.AddHours(3);
DateTime t5 = t1.AddHours(4);
Task task1 = Task.CreateUsingQuantity(t2, t3, 100);
Task task2 = Task.CreateUsingQuantity(t1, t3, -60);
Task task3 = Task.CreateUsingQuantity(t4, t5, -10);
taskCollection.Add(task1);
taskCollection.Add(task2);
taskCollection.Add(task3);
// Act
IEnumerable<ITask> newCollection = taskCollection.TryToMakeTasksComply(minLevel, maxLevel, initialLevel);
// Assert
Assert.AreNotEqual(newCollection.Single(task => task.TaskType == TaskType.Produce).EndTime, t4);
var consumingTasks = newCollection.Where(task => task.TaskType == TaskType.Consume).ToList();
Assert.True(consumingTasks[0].Equals(task2));
Assert.True(consumingTasks[1].Equals(task3));
Assert.True( newCollection.GetDataPoints( initialLevel ).Select( x => x.Value ).Max() == maxLevel ); // Quantity level just touches the max level
Assert.True(newCollection.WillStayWithinRange(minLevel, maxLevel, initialLevel));
}
示例5: TryToMakeTasksComply_MixedData_ReturnsCorrectCollection6
public void TryToMakeTasksComply_MixedData_ReturnsCorrectCollection6()
{
// Arrange
double minLevel = 100;
double maxLevel = 1000;
double initialLevel = 100;
var taskCollection = new Collection<ITask>();
DateTime t1 = DateTime.Now;
DateTime t2 = t1.AddHours(1);
DateTime t3 = t1.AddHours(2);
DateTime t4 = t3.AddHours(10);
Task task1 = Task.CreateUsingQuantityPerHour(t1, t2, 10000); // NOTE: Using QuantityPerHour here.
Task task2 = Task.CreateUsingQuantityPerHour(t3, t4, -1000);
taskCollection.Add(task1);
taskCollection.Add(task2);
// Act
IEnumerable<ITask> newCollection = taskCollection.TryToMakeTasksComply(minLevel, maxLevel, initialLevel);
// Assert
// Assert
Assert.Null(newCollection);
}
示例6: TryToMakeTasksComply_MixedData_ReturnsCorrectCollection5
public void TryToMakeTasksComply_MixedData_ReturnsCorrectCollection5()
{
double minLevel = 100;
double maxLevel = 200;
double initialLevel = 100;
var taskCollection = new Collection<ITask>();
DateTime t1 = DateTime.Now;
DateTime t2 = t1.AddHours(1);
DateTime t3 = t1.AddHours(2);
DateTime t4 = t1.AddHours(3);
DateTime t5 = t1.AddHours(4);
DateTime t6 = t1.AddHours(5);
DateTime t7 = t1.AddHours(6);
DateTime t8 = t1.AddHours(7);
initialLevel = 150;
Task task1 = Task.CreateUsingQuantity(t2, t3, -150);
Task task2 = Task.CreateUsingQuantity(t2.AddHours(0.5), t3.AddHours(0.5), -100);
Task task3 = Task.CreateUsingQuantity(t3, t4, -50);
Task task4 = Task.CreateUsingQuantity(t4, t5, 50);
Task task5 = Task.CreateUsingQuantity(t5, t6, 50);
Task task6 = Task.CreateUsingQuantity(t5, t7, 100);
Task task7 = Task.CreateUsingQuantity(t7, t8, 150);
taskCollection.Add(task1);
taskCollection.Add(task2);
taskCollection.Add(task3);
taskCollection.Add(task4);
taskCollection.Add(task5);
taskCollection.Add(task6);
taskCollection.Add(task7);
// Act
IEnumerable<ITask> newCollection = taskCollection.TryToMakeTasksComply(minLevel, maxLevel, initialLevel);
var correctCollection = new Collection<ITask>();
correctCollection.Add(task1.ChangeTimes(t4.AddMinutes(30)));
correctCollection.Add(task2.ChangeTimes(t6.AddMinutes(20)));
correctCollection.Add(task3.ChangeTimes(t6.AddMinutes(20)));
correctCollection.Add(task4);
correctCollection.Add(task5);
correctCollection.Add(task6);
correctCollection.Add(task7);
// OLD TEST DATA
//correctCollection.Add(task1.ChangeTimes(t5));
//correctCollection.Add(task2.ChangeTimes(t6));
//correctCollection.Add(task3.ChangeTimes(t7));
//correctCollection.Add(task4);
//correctCollection.Add(task5);
//correctCollection.Add(task6);
//correctCollection.Add(task7);
Assert.AreEqual(correctCollection, newCollection);
}
示例7: TryToMakeTasksComply_MixedData_ReturnsCorrectCollection4
public void TryToMakeTasksComply_MixedData_ReturnsCorrectCollection4()
{
double minLevel = 100;
double maxLevel = 200;
double initialLevel = 100;
var taskCollection = new Collection<ITask>();
DateTime t1 = DateTime.Now;
DateTime t2 = t1.AddHours(1);
DateTime t3 = t1.AddHours(2);
DateTime t4 = t1.AddHours(3);
DateTime t5 = t1.AddHours(4);
DateTime t6 = t1.AddHours(5);
DateTime t7 = t1.AddHours(6);
DateTime t8 = t1.AddHours(7);
Task task1 = Task.CreateUsingQuantity(t1, t6, 500);
Task task2 = Task.CreateUsingQuantity(t1, t2, -200);
Task task3 = Task.CreateUsingQuantity(t3, t4, -100);
Task task4 = Task.CreateUsingQuantity(t4, t5, -200);
Task task5 = Task.CreateUsingQuantity(t6, t7, -100);
Task task6 = Task.CreateUsingQuantity(t7, t8, -200);
Task task7 = Task.CreateUsingQuantity(t7, t8, 300);
taskCollection.Add(task1);
taskCollection.Add(task2);
taskCollection.Add(task3);
taskCollection.Add(task4);
taskCollection.Add(task5);
taskCollection.Add(task6);
taskCollection.Add(task7);
// Act
IEnumerable<ITask> newCollection = taskCollection.TryToMakeTasksComply(minLevel, maxLevel, initialLevel);
var correctCollection = new Collection<ITask>();
correctCollection.Add(task1);
correctCollection.Add(task2.ChangeTimes(t2));
correctCollection.Add(task3);
correctCollection.Add(task4.ChangeTimes(t5));
correctCollection.Add(task5.ChangeTimes(t7));
correctCollection.Add(task6);
correctCollection.Add(task7);
Assert.AreEqual(correctCollection, newCollection);
}
示例8: TryToMakeTasksComply_MixedData_ReturnsCorrectCollection2
public void TryToMakeTasksComply_MixedData_ReturnsCorrectCollection2()
{
double minLevel = 100;
double maxLevel = 200;
double initialLevel = 100;
var taskCollection = new Collection<ITask>();
DateTime t1 = DateTime.Now;
DateTime t2 = t1.AddHours(1);
DateTime t3 = t1.AddHours(2);
DateTime t4 = t1.AddHours(3);
Task task1 = Task.CreateUsingQuantity(t1, t2, -200);
Task task2 = Task.CreateUsingQuantity(t2, t3, -200);
Task task3 = Task.CreateUsingQuantity(t3, t4, 400);
taskCollection.Add(task1);
taskCollection.Add(task2);
taskCollection.Add(task3);
// Act
IEnumerable<ITask> newCollection = taskCollection.TryToMakeTasksComply(minLevel, maxLevel, initialLevel);
var correctCollection = new Collection<ITask>();
correctCollection.Add(task1.ChangeTimes(t3));
correctCollection.Add(task2.ChangeTimes(t3));
correctCollection.Add(task3);
Assert.AreEqual(correctCollection, newCollection);
}
示例9: TryToMakeTasksComply_IfImpossible_ReturnsNull
public void TryToMakeTasksComply_IfImpossible_ReturnsNull()
{
// Arrange
var taskCollection = new Collection<ITask>();
DateTime t1 = DateTime.Now;
DateTime t2 = t1.AddHours(2);
taskCollection.Add(Task.CreateUsingQuantity(t1, t2, 110));
// Act
IEnumerable<ITask> value = taskCollection.TryToMakeTasksComply(100, 200, 100);
// Assert
Assert.Null( value );
}