public void Matches_should_report_fuzzy_comparer() { var subj = new EqualMatcher <double>(1.0).OrClose(0.2); var failure = TestMatcherLocalizer.Failure(subj, 0.0); Assert.ContainsKeyWithValue("Comparer", "close by 0.2", failure.UserData); }
public void CanCompareAutoboxedValues() { Matcher matcher = new EqualMatcher(1); Assert.IsTrue(matcher.Matches(1), "equal value"); Assert.IsFalse(matcher.Matches(2), "other value"); }
public void Matches_should_report_string_comparer() { var subj = new EqualMatcher <string>("A", StringComparer.OrdinalIgnoreCase); var failure = TestMatcherLocalizer.Failure(subj, "A"); Assert.ContainsKeyWithValue("Comparer", "ordinal (ignore case)", failure.UserData); }
public void TestFailure_from_long_string_should_produce_diff() { var subj = new EqualMatcher <string>(@"and bool count double epsilon"); var failure = TestMatcherLocalizer.Failure(subj, @"and bool c d e"); Assert.NotNull(failure.UserData.Diff); var diff = failure.UserData.Diff.ToString().Split(new [] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries); Assert.Equal(new [] { "@@@ -1,6 +1,6", " and", " bool", "-count", "-double", "-epsilon", "+c", "+d", "+e" }, diff); }
public void TestFailure_from_short_string_should_not_produce_diff() { var subj = new EqualMatcher <string>("and"); var failure = TestMatcherLocalizer.Failure(subj, "bool"); Assert.Null(failure.UserData.Diff); }
public void ComparesArgumentForEqualityToExpectedObject() { Matcher matcher = new EqualMatcher(EXPECTED); Assert.IsTrue(matcher.Matches(EXPECTED), "same object"); #if !SILVERLIGHT Assert.IsTrue(matcher.Matches(EXPECTED.Clone()), "equal object"); #endif Assert.IsFalse(matcher.Matches("not expected"), "unequal object"); }
public void RecursivelyComparesArrayContentsOfNestedArrays() { int[][] expected = new[] { new[] { 1, 2 }, new[] { 3, 4 } }; int[][] equal = new[] { new[] { 1, 2 }, new[] { 3, 4 } }; int[][] inequal = new[] { new[] { 2, 3 }, new[] { 4, 5 } }; Matcher matcher = new EqualMatcher(expected); Assert.IsTrue(matcher.Matches(expected), "same array"); Assert.IsTrue(matcher.Matches(equal), "same contents"); Assert.IsFalse(matcher.Matches(inequal), "different contents"); }
public void ComparesMultidimensionalArraysForEquality() { int[,] expected = { { 1, 2 }, { 3, 4 } }; int[,] equal = { { 1, 2 }, { 3, 4 } }; int[,] inequal = { { 3, 4 }, { 5, 6 } }; int[,] empty = new int[0, 0]; int[] otherRank = { 1, 2 }; Matcher matcher = new EqualMatcher(expected); Assert.IsTrue(matcher.Matches(expected), "same array"); Assert.IsTrue(matcher.Matches(equal), "same contents"); Assert.IsFalse(matcher.Matches(inequal), "different contents"); Assert.IsFalse(matcher.Matches(empty), "empty"); Assert.IsFalse(matcher.Matches(otherRank), "other rank"); }
public void ComparesArraysForEqualityByContents() { int[] expected = { 1, 2 }; int[] equal = { 1, 2 }; int[] inequal = { 2, 3 }; int[] longer = { 1, 2, 3 }; int[] shorter = { 1 }; int[] empty = {}; int[,] otherRank = { { 1, 2 }, { 3, 4 } }; Matcher matcher = new EqualMatcher(expected); Assert.IsTrue(matcher.Matches(expected), "same array"); Assert.IsTrue(matcher.Matches(equal), "same contents"); Assert.IsFalse(matcher.Matches(inequal), "different contents"); Assert.IsFalse(matcher.Matches(longer), "longer"); Assert.IsFalse(matcher.Matches(shorter), "shorter"); Assert.IsFalse(matcher.Matches(empty), "empty"); Assert.IsFalse(matcher.Matches(otherRank), "other rank"); }
public void RecursivelyComparesContentsOfNestedLists() { ArrayList expected = new ArrayList(new[] { new ArrayList(new[] { 1, 2 }), new ArrayList(new[] { 3, 4 }) }); ArrayList equal = new ArrayList(new[] { new ArrayList(new[] { 1, 2 }), new ArrayList(new[] { 3, 4 }) }); ArrayList inequal = new ArrayList(new[] { new ArrayList(new[] { 2, 3 }), new ArrayList(new[] { 4, 5 }) }); Matcher matcher = new EqualMatcher(expected); Assert.IsTrue(matcher.Matches(expected), "same array"); Assert.IsTrue(matcher.Matches(equal), "same contents"); Assert.IsFalse(matcher.Matches(inequal), "different contents"); }
public void HasAReadableDescription() { Matcher matcher = new EqualMatcher("foo"); AssertDescription.IsEqual(new PropertyMatcher("A", matcher), "property 'A' " + matcher); }
public void HasAReadableDescription() { Matcher matcher = new EqualMatcher("foo"); AssertDescription.IsEqual(new FieldMatcher("A", matcher), "field 'A' " + matcher); }
public void Matches_should_apply_approximation() { var subj = new EqualMatcher <double>(5.0).OrClose(0.03); Assert.True(subj.Matches(5.02)); }
public void Matches_should_detect_strings_string_comparison() { var subj = new EqualMatcher <string>("A", StringComparer.OrdinalIgnoreCase); Assert.True(subj.Matches("a")); }
public void Matches_should_detect_substrings_nominal() { var subj = new EqualMatcher <string>("a"); Assert.True(subj.Matches("a")); }