matlab类中增加公共属性,在递归中支持任何值的公共属性比较器

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

import matlab.unittest.TestCase

import matlab.unittest.constraints.IsEqualTo

import matlab.unittest.constraints.RelativeTolerance

import matlab.unittest.constraints.PublicPropertyComparator

testCase = TestCase.forInteractiveUse;

定义实际和预期 timeseries 对象。将一个实际数据点扰动 1%。

expected = timeseries(1:10);

actual = expected;

actual.Data(7) = 1.01*actual.Data(7);

测试是否实际值和预期值在 2% 的相对误差界限内相等。

testCase.verifyThat(actual, IsEqualTo(expected,...

'Within', RelativeTolerance(.02)))

Verification failed.

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

Framework Diagnostic:

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

IsEqualTo failed.

--> ObjectComparator failed.

--> The objects are not equal using "isequal".

--> The tolerance was ignored. The tolerance as specified does not support comparisons of timeseries values.

Actual timeseries:

timeseries

Common Properties:

Name: 'unnamed'

Time: [10x1 double]

TimeInfo: [1x1 tsdata.timemetadata]

Data: [1x1x10 double]

DataInfo: [1x1 tsdata.datametadata]

More properties, Methods

Expected timeseries:

timeseries

Common Properties:

Name: 'unnamed'

Time: [10x1 double]

TimeInfo: [1x1 tsdata.timemetadata]

Data: [1x1x10 double]

DataInfo: [1x1 tsdata.datametadata]

More properties, Methods

在构造约束时使用 PublicPropertyComparator。

testCase.verifyThat(actual, IsEqualTo(expected,...

'Within', RelativeTolerance(.02),...

'Using', PublicPropertyComparator.supportingAllValues))

Interactive verification passed.

测试通过,原因是 PublicPropertyComparator 分别比较每个公共属性而不是一次性比较该对象。在前一测试中,ObjectComparator 比较 timeseries 对象,因此依赖于 timeseries 类的 isequal 方法。由于实际 timeseries 中的扰动,isequal 返回 false。比较器不应用该容差,原因是双精度值容差不能直接应用于 timeseries 对象。在后一测试中,比较器将容差应用于包含双精度值数据的每个公共属性。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值