public void FirstElement() { var diff = new StringDiff("qabc", "xabc"); var result = diff.Compute(); result.Print(); }
public void NoChanges() { var diff = new StringDiff("foo", "foo"); var result = diff.Compute(); Assert.AreEqual(3, result.Changes.Count()); Assert.AreEqual(0, result.Additions); Assert.AreEqual(0, result.Deletions); }
public void DiffCommonPrefix() { var diff = new StringDiff("abcdfghjqz", "abcdefgijkrxyz"); var result = diff.Compute(); result.Print(); Assert.AreEqual(6, result.Additions); Assert.AreEqual(2, result.Deletions); Assert.AreEqual(16, result.Changes.Count()); }
public void DiffBanana() { var diff = new StringDiff("banana", "atana"); // var diff = new StringDiff("atana", "banana"); var result = diff.Compute(); result.Print(); Assert.AreEqual(1, result.Additions); Assert.AreEqual(2, result.Deletions); Assert.AreEqual(7, result.Changes.Count()); }
/// <summary> /// Computes a <see cref="DiscrepancyTestResult"/> for a specified property /// </summary> /// <typeparam name="T">The type of the property being tested</typeparam> /// <param name="x">Left operand</param> /// <param name="y">Right operand</param> /// <param name="discrepancy">Discrepancy being tested</param> /// <param name="getter">A delegate that returns the value of the property from a <see cref="PatientProfile"/></param> /// <param name="tester">A delegate that tests for equality of the property - need not be null-safe</param> /// <param name="toString">A delegate that converts the property to a string</param> /// <returns></returns> private static DiscrepancyTestResult GetResult <T>(PatientProfile x, PatientProfile y, PatientProfileDiscrepancy discrepancy, PropertyGetter <T> getter, TestEqual <T> tester, ToStringDelegate <T> toString) { var vx = getter(x); var vy = getter(y); if (Equals(vx, default(T)) && Equals(vy, default(T))) { return(new DiscrepancyTestResult(discrepancy, false, StringDiff.Compute("", "", true))); } if (Equals(vx, default(T))) { return(new DiscrepancyTestResult(discrepancy, true, StringDiff.Compute("", toString(vy), true))); } if (Equals(vy, default(T))) { return(new DiscrepancyTestResult(discrepancy, true, StringDiff.Compute(toString(vx), "", true))); } return(new DiscrepancyTestResult(discrepancy, !tester(vx, vy), StringDiff.Compute(toString(vx), toString(vy), true))); }