Create Custom Tolerance
This example shows how to create a custom tolerance to determine if two DNA sequences
have a Hamming distance within a specified tolerance. For two DNA sequences of the
same length, the Hamming distance is the number of positions in which the nucleotides
(letters) of one sequence differ from the other.In a file, DNA.m, in your working folder, create a simple class for a DNA sequence.classdef DNA
properties(SetAccess=immutable)
Sequence
endmethods
function dna = DNA(sequence)
validLetters = ...
sequence == 'A' | ...
sequence == 'C' | ...
sequence == 'T' | ...
sequence == 'G';if ~all(validLetters(:))
error('Sequence contained a letter not found in DNA.')
end
dna.Sequence = sequence;
end
end
endIn a file in your working folder, create a tolerance class so that you can test that DNA
sequences are within a specified Hamming distance. The constructor requires a Value
property that defines the maximum Hamming distance.classdef HammingDistance < matlab.unittest.constraints.Tolerance
properties
Value
endmethods
function tolerance = HammingDistance(value)
tolerance.Value = value;
end33 Unit Testing