public void Constructor_AssignsPropertiesCorrectly(int p1, int p2, int l) { var lcsr = new LongestCommonSubstringResult(p1, p2, l); Assert.That(lcsr.PositionInCollection1, Is.EqualTo(p1)); Assert.That(lcsr.PositionInCollection2, Is.EqualTo(p2)); Assert.That(lcsr.Length, Is.EqualTo(l)); }
/////////////////////////////////////////////////////////////// // rest is from part 2, modified for recursive sections public static LongestCommonSubstringResult FindLongestCommonSubstring( string firstCollection, int firstStart, int firstEnd, string secondCollection, int secondStart, int secondEnd, IEqualityComparer <char> equalityComparer) { // default result, if we can't find anything var result = new LongestCommonSubstringResult(); for (int index1 = firstStart; index1 < firstEnd; index1++) { for (int index2 = secondStart; index2 < secondEnd; index2++) { if (equalityComparer.Equals( firstCollection[index1], secondCollection[index2])) { int length = CountEqual( firstCollection, index1, firstEnd, secondCollection, index2, secondEnd, equalityComparer); // Is longer than what we already have --> record new LCS if (length > result.Length) { result = new LongestCommonSubstringResult( true, index1, index2, length); } } } } return(result); }
public DiffSection(DiffSectionType type, LongestCommonSubstringResult lcs) { Type = type; LCS = lcs; }