当前位置: 首页>>代码示例>>C#>>正文


C# Collection.TryToMakeTasksComply方法代码示例

本文整理汇总了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));
        }
开发者ID:Orcomp,项目名称:Orcomp,代码行数:27,代码来源:TaskCollectionExtensionTest.cs

示例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));
        }
开发者ID:Orcomp,项目名称:Orcomp,代码行数:33,代码来源:TaskCollectionExtensionTest.cs

示例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));
        }
开发者ID:Orcomp,项目名称:Orcomp,代码行数:35,代码来源:TaskCollectionExtensionTest.cs

示例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));
        }
开发者ID:Orcomp,项目名称:Orcomp,代码行数:30,代码来源:TaskCollectionExtensionTest.cs

示例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);
        }
开发者ID:Orcomp,项目名称:Orcomp,代码行数:24,代码来源:TaskCollectionExtensionTest.cs

示例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);
        }
开发者ID:Orcomp,项目名称:Orcomp,代码行数:55,代码来源:TaskCollectionExtensionTest.cs

示例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);
        }
开发者ID:Orcomp,项目名称:Orcomp,代码行数:44,代码来源:TaskCollectionExtensionTest.cs

示例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);
        }
开发者ID:Orcomp,项目名称:Orcomp,代码行数:28,代码来源:TaskCollectionExtensionTest.cs

示例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 );
        }
开发者ID:Orcomp,项目名称:Orcomp,代码行数:14,代码来源:TaskCollectionExtensionTest.cs


注:本文中的Collection.TryToMakeTasksComply方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。