コード例 #1
0
ファイル: TriggerTTests.cs プロジェクト: vscode1111/Usable
        public void CalculateRet_Bool()
        {
            TriggerT <bool> trigger = new TriggerT <bool>();

            trigger.Calculate(true);
            Assert.IsTrue(trigger.Calculate(false));
        }
コード例 #2
0
ファイル: TriggerTTests.cs プロジェクト: vscode1111/Usable
        public void CalculateRet_Int()
        {
            TriggerT <int> trigger = new TriggerT <int>();

            trigger.Calculate(6);
            Assert.IsTrue(trigger.Calculate(5));
        }
コード例 #3
0
        /// <summary>
        /// Ожидание измений статуса пульта управления.
        /// </summary>
        /// <returns></returns>
        public Task <bool> WaitControlStatusChanged()
        {
            TriggerT <bool> trgAllow = new TriggerT <bool>(ControlStatus.btnAllow);
            TriggerT <bool> trgDeny  = new TriggerT <bool>(ControlStatus.btnDeny);

            Task <bool> task = new Task <bool>(() =>
            {
                while (true)
                {
                    if (trgAllow.Calculate(ControlStatus.btnAllow) ||
                        trgDeny.Calculate(ControlStatus.btnDeny))
                    {
                        return(true);
                    }

                    Thread.Sleep(100);
                }
            });

            return(task.WithTimeout(TimeSpan.FromSeconds(60), true, "WaitControlStatusChanged exeption"));
        }
コード例 #4
0
        /// <summary>
        /// Метод тестрирования под различным количеством потоквов.
        /// </summary>
        /// <param name="poolCount"></param>
        public void ExecuteTest_AnyPoolWithPriority(int poolCount)
        {
            TestConditions result = new TestConditions();

            // перенос из стека в память.
            int poolCountCopy = (int)(object)poolCount;

            FixedThreadPool pool = new FixedThreadPool(poolCountCopy);

            Collection <TaskInfo> infoInit  = new Collection <TaskInfo>();
            Collection <TaskInfo> infoAfter = new Collection <TaskInfo>();

            Random rnd = new Random();
            int    pr;

            const int attemps = 100;

            for (int i = 0; i < attemps; i++)
            {
                TaskPriorityEx priority;
                pr = rnd.Next(0, 3);

                switch (pr)
                {
                case 0:
                    priority = TaskPriorityEx.LOW;
                    break;

                case 1:
                    priority = TaskPriorityEx.NORMAL;
                    break;

                case 2:
                    priority = TaskPriorityEx.HIGH;
                    break;

                default:
                    priority = TaskPriorityEx.LOW;
                    break;
                }

                int copyI = i;
                infoInit.Add(new TaskInfo(copyI, priority, DateTime.Now));
                if (!pool.Execute(
                        () =>
                {
                    infoAfter.Add(new TaskInfo(copyI, priority, DateTime.Now));
                    Console.WriteLine(string.Format("Task {0} {1}", copyI, priority));
                    Thread.Sleep(30);
                },
                        priority))
                {
                    result.Add(() => false, () => "Void Execute return FALSE unexpectedly");
                }
            }

            Thread.Sleep((int)(attemps * 30 / (double)poolCountCopy) + 1000);

            int            noNormalCount = 0;
            int            normalStep    = 0;
            TriggerT <int> trgNormal     = new TriggerT <int>();

            for (int i = 0; i < attemps; i++)
            {
                int copyI = i;
                if (i < poolCountCopy)
                {
                    IEnumerable <TaskInfo> infors = infoInit.Where(item => item.Id == infoAfter[i].Id);
                    if (infors.Count() > 0)
                    {
                        infoInit.Remove(infors.First());
                    }
                    else
                    {
                        result.Add(() => false, () => string.Format("{0} is bad", copyI));
                    }
                }
                else
                {
                    IEnumerable <TaskInfo> infors = infoInit.Where(item => item.Id == infoAfter[i].Id);
                    if (infors.Count() > 0)
                    {
                        if (infors.First().Priority == TaskPriorityEx.NORMAL)
                        {
                            normalStep = i;
                        }
                        else
                        {
                            if (normalStep == 0)
                            {
                                noNormalCount++;
                            }
                        }

                        if (noNormalCount > 5)
                        {
                            result.Add(() => false, () => string.Format("{0} - NORMAL doesn't exist to long", copyI));
                        }

                        int normalStCp = normalStep;

                        if (normalStCp < 30)
                        {
                            if (trgNormal.Calculate(normalStep))
                            {
                                result.Add(() =>
                                {
                                    if (infoAfter[normalStCp + 1].Priority == TaskPriorityEx.HIGH &&
                                        infoAfter[normalStCp + 2].Priority == TaskPriorityEx.HIGH &&
                                        infoAfter[normalStCp + 3].Priority == TaskPriorityEx.HIGH &&
                                        infoAfter[normalStCp + 4].Priority == TaskPriorityEx.NORMAL)
                                    {
                                        return(true);
                                    }
                                    else
                                    {
                                        return(false);
                                    }
                                }, () => string.Format("{0} - Not accurate orders of HIGH and NORMAL", copyI));
                            }
                        }

                        infoInit.Remove(infors.First());
                    }
                    else
                    {
                        result.Add(() => false, () => string.Format("{0} - is bad", copyI));
                    }
                }
            }

            result.Print();
            Assert.IsTrue(result.Calculate());
        }