Example #1
0
    public void Contains_100000_Elements_ShouldExecuteFast()
    {
        // Arrange
        IScheduler        executor = new ThreadExecutor();
        const int         count    = 100000;
        LinkedList <Task> tasks    = new LinkedList <Task>();

        for (int i = 0; i < count; i++)
        {
            tasks.AddLast(new Task(i, i, Priority.HIGH));
            executor.Execute(tasks.Last.Value);
        }

        // Act
        Stopwatch             sw   = Stopwatch.StartNew();
        LinkedListNode <Task> node = tasks.First;

        while (node != null)
        {
            Assert.True(executor.Contains(node.Value));
            node = node.Next;
        }

        sw.Stop();
        Assert.Less(sw.ElapsedMilliseconds, 250);
    }
Example #2
0
    public void Contains_ThreadExecutor_ShouldWorkCorrectly_AfterCycle()
    {
        //Arrange
        IScheduler executor = new ThreadExecutor();

        Task task1 = new Task(52, 12, Priority.EXTREME);
        Task task2 = new Task(13, 8, Priority.HIGH);

        //Act
        executor.Execute(task1);
        executor.Execute(task2);

        executor.Cycle(5);

        Assert.True(executor.Contains(task2));

        executor.Cycle(3);

        //Assert
        Assert.AreEqual(1, executor.Count);
        Assert.False(executor.Contains(task2));
    }