import matlab.unittest.diagnostics.StringDiagnostic
if ~isSameSize(actual.Sequence, expected.Sequence)
str = 'The DNA sequences must be the same length.';
else
str = sprintf('%s%d.\n%s%d.', ...
'The DNA sequences have a Hamming distance of ', ...
hammingDistance(actual.Sequence, expected.Sequence), ...
'The allowable distance is ', ...
tolerance.Value);
end
diag = StringDiagnostic(str);
end
end
end
function tf = isSameSize(str1, str2)
tf = isequal(size(str1), size(str2));
end
function distance = hammingDistance(str1, str2)
distance = nnz(str1 ~= str2);
end
At the command prompt, create a TestCase for interactive testing.
import matlab.unittest.TestCase
import matlab.unittest.constraints.IsEqualTo
testCase = TestCase.forInteractiveUse;
Create two DNA objects.
sampleA = DNA('ACCTGAGTA');
sampleB = DNA('ACCACAGTA');
Verify that the DNA sequences are equal to each other.
testCase.verifyThat(sampleA, IsEqualTo(sampleB))
Interactive verification failed.
Framework Diagnostic:
Create Custom Tolerance