end
end
In a methods block with the HammingDistance class definition, include the following
method so that the tolerance supports DNA objects. Tolerance classes must implement a
supports method.
methods
function tf = supports(~, value)
tf = isa(value, 'DNA');
end
end
In a methods block with the HammingDistance class definition, include the following
method that returns true or false. Tolerance classes must implement a satisfiedBy
method. The testing framework uses this method to determine if two values are within the
tolerance.
methods
function tf = satisfiedBy(tolerance, actual, expected)
if ~isSameSize(actual.Sequence, expected.Sequence)
tf = false;
return
end
tf = hammingDistance(actual.Sequence,expected.Sequence) <= tolerance.Value;
end
end
In the HammingDistance.m file, define the following helper functions outside of the
classdef block. The isSameSize function returns true if two DNA sequences are the
same size, and the hammingDistance function returns the Hamming distance between
two sequences.
function tf = isSameSize(str1, str2)
tf = isequal(size(str1), size(str2));
end
function distance = hammingDistance(str1, str2)
distance = nnz(str1 ~= str2);
end
The function returns a Diagnostic object with information about the comparison. In a
methods block with the HammingDistance class definition, include the following method
Create Custom Tolerance