public void DiffDetecsWhenInputStringsHaveSameSizeButDifferentContent() { var customDiff = new CustomDiff("this iz on imtot string", "this is an input steeeg"); var customDiffResult = customDiff.Diff(); Assert.Equal("The compared strings have the same size but the content is different", customDiffResult.Result); Assert.True(customDiffResult.Differences.Count > 0); Assert.Equal(6, customDiffResult.Differences[0].StartPosition); Assert.Equal(1, customDiffResult.Differences[0].Length); Assert.Equal(8, customDiffResult.Differences[1].StartPosition); Assert.Equal(1, customDiffResult.Differences[1].Length); Assert.Equal(12, customDiffResult.Differences[2].StartPosition); Assert.Equal(3, customDiffResult.Differences[2].Length); Assert.Equal(19, customDiffResult.Differences[3].StartPosition); Assert.Equal(3, customDiffResult.Differences[3].Length); }
public IActionResult Get(int id) { // Returns 404 if Id hasn't been inserted in both directions. This prevents an unwanted 500 from raising to the user. if (!CachingHelper.KeyExists(id)) { return(new NotFoundObjectResult("Provided Id does not exist")); } string left = CachingHelper.Get(id, CacheDirection.LEFT); string right = CachingHelper.Get(id, CacheDirection.RIGHT); /* Improvement: If this application did a heavier/more complex Diff, instead of calling the Diff on the GET, there could be an async/background worker * that ran whenever both directions were input, making the GET speed faster */ var diffResult = new CustomDiff(left, right).Diff(); var response = new DiffResultView { Result = diffResult.Result, Extra = diffResult.HasDifferences ? diffResult.Differences.ToString() : "" }; return(new JsonResult(response)); }
public void DiffDetecsWhenOneInputStringIsEmpty() { var customDiffResult = new CustomDiff("this is an input string", "").Diff(); Assert.Equal("The compared strings have different sizes", customDiffResult.Result); }
public void DiffDetecsWhenInputStringsAreEqual() { var customDiffResult = new CustomDiff("this is an input string", "this is an input string").Diff(); Assert.Equal("The compared strings are equal", customDiffResult.Result); }