概述
在工作文件夹下的文件中,构造 Employee 类。
classdef Employee
properties (SetAccess=immutable)
Name
end
properties (Access=private)
Location
end
methods
function obj = Employee(name,location)
obj.Name = name;
obj.Location = location;
end
end
end
在命令提示符处,创建 Employee 类的两个实例。
e1 = Employee('sam','Building A');
e2 = Employee('Sam','Building B');
创建一个供交互测试的测试用例。
import matlab.unittest.TestCase
import matlab.unittest.constraints.IsEqualTo
import matlab.unittest.constraints.PublicPropertyComparator
import matlab.unittest.constraints.StringComparator
testCase = TestCase.forInteractiveUse;
构造一个比较器并验证 e1 和 e2 是否相等。
compObj = PublicPropertyComparator;
testCase.verifyThat(e1, IsEqualTo(e2,'Using',compObj))
Error using matlab.unittest.constraints.Comparator/throwUnsupportedValue (line 313)
None of the currently available comparators support the value.
Available Comparators:
1×0 Comparator array with no properties.
Value (char):
Sam
Error in matlab.unittest.constraints.Comparator>getActExpCompFrom (line 402)
throwUnsupportedValue(comparison.Comparators,expVal);
Error in matlab.unittest.constraints.Comparator>deepComparisonIsSatisfied (line 351)
[actVal,expVal,comp] = getActExpCompFrom(comparison);
Error in matlab.unittest.constraints.Comparator>deepComparisonIsSatisfied (line 355)
if ~deepComparisonIsSatisfied(subComparisonArray(k))
Error in matlab.unittest.constraints.Comparator/satisfiedBy (line 84)
bool = deepComparisonIsSatisfied(comparison);
Error in matlab.unittest.constraints.IsEqualTo/satisfiedBy (line 193)
bool = constraint.Comparator.satisfiedBy(actual,constraint.Expected);
Error in matlab.unittest.internal.qualifications.QualificationDelegate/qualifyThat (line 80)
result = constraint.satisfiedBy(actual);
Error in matlab.unittest.qualifications.Verifiable/verifyThat (line 230)
qualifyThat(verifiable.VerificationDelegate, ...
测试失败,原因是默认情况下 PublicPropertyComparator 不支持字符向量。
构造一个支持字符向量的比较器。指定比较不区分大小写。
compObj = PublicPropertyComparator(StringComparator);
testCase.verifyThat(e1, IsEqualTo(e2,'Using',compObj, 'IgnoringCase',true))
Interactive verification passed.
即使 e1.Location 和 e2.Location 不相同,测试也将通过。由于 Location 为私有属性,比较器将不比较其内容。
最后
以上就是爱撒娇滑板为你收集整理的比较器matlab,用于比较 MATLAB 对象的公共属性的比较器 - MATLAB - MathWorks 中国的全部内容,希望文章能够帮你解决比较器matlab,用于比较 MATLAB 对象的公共属性的比较器 - MATLAB - MathWorks 中国所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复