/// <summary> /// Constructs a new <see cref="ElementSimilarityDiffElementAligner{T}"/>. /// </summary> /// <param name="similarityFunc"> /// A <see cref="ElementSimilarity{T}"/> delegate that is used to work out how similar two elements are. /// </param> /// <param name="modificationThreshold"> /// A threshold value used to determine if aligned elements are considered replacements or modifications. If /// two items are more similar than the threshold specifies (similarity > threshold), then it results in /// a <see cref="DiffOperation.Modify"/>, otherwise it results in a <see cref="DiffOperation.Replace"/>. /// </param> /// <exception cref="ArgumentNullException"> /// <para><paramref name="similarityFunc"/> is <c>null</c>.</para> /// </exception> public ElementSimilarityDiffElementAligner([NotNull] ElementSimilarity <T> similarityFunc, double modificationThreshold = 0.3333) { if (similarityFunc == null) { throw new ArgumentNullException(nameof(similarityFunc)); } _SimilarityFunc = similarityFunc; _ModificationThreshold = modificationThreshold; }
public void ElementSimilarityDiffElementAlignerTestCases(string s1, string s2, string expected) { ElementSimilarity <char> aligner = delegate(char element1, char element2) { if (element1 == element2) { return(1.0); } if (char.ToUpper(element1) == char.ToUpper(element2)) { return(0.75); } return(0.0); }; var sections = Diff.CalculateSections(s1.ToCharArray(), s2.ToCharArray()); var elements = Diff.AlignElements(s1.ToCharArray(), s2.ToCharArray(), sections, new ElementSimilarityDiffElementAligner <char>(aligner)); var output = GetElementOperationsAsAString(elements); Assert.That(output, Is.EqualTo(expected)); }