matlab轮询调度算法代码,轮询值以找到能以异步方式满足约束

创建一个供交互测试的测试用例。

import matlab.unittest.TestCase

import matlab.unittest.constraints.Eventually

import matlab.unittest.constraints.IsGreaterThan

import matlab.unittest.constraints.IsLessThan

testCase = TestCase.forInteractiveUse;

验证在时限内调用 toc 得到的值大于 10(秒)。Eventually 约束重复调用 toc,直至满足约束或者所用时间超过时限。重复调用 toc 的所用时间自上次调用 tic 起计。

tic

testCase.verifyThat(@toc, Eventually(IsGreaterThan(10)))

Interactive verification passed.

验证过程可能需要长达 10 秒钟,toc 才能获得通过值。如果发出对 tic 的调用并等待 10 秒以上,然后再发出 verifyThat 命令,则验证过程将立即返回结果,因为 toc 已返回大于 10 的值。

确认在时限内 toc 未返回负值。

testCase.verifyThat(@toc, Eventually(IsLessThan(0)))

Interactive verification failed.

---------------------

Framework Diagnostic:

---------------------

Eventually failed.

--> The constraint never passed with a timeout of 20 second(s).

--> IsLessThan failed.

--> The value must be less than the maximum value.

Actual Value:

36.532254706346720

Maximum Value (Exclusive):

0

Evaluated Function:

function_handle with value:

@toc

由于已用时间不会小于零,因此可预期会失败。但是,Eventually 在整个超时期限内轮询 toc。

调整时限,以便 Eventually 轮询 5 秒。

tic

testCase.verifyThat(@toc, Eventually(IsGreaterThan(10), ...

'WithTimeoutOf', 5))

Interactive verification failed.

---------------------

Framework Diagnostic:

---------------------

Eventually failed.

--> The constraint never passed with a timeout of 5 second(s).

--> IsGreaterThan failed.

--> The value must be greater than the minimum value.

Actual Value:

5.143138452046230

Minimum Value (Exclusive):

10

Evaluated Function:

function_handle with value:

@toc

如果在调用 tic 和 verifyThat 之间未等待 5 秒以上,则测试将失败,原因是所用时间不超过 10 秒,在更改后的时限内。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值