Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        public void CanCompareAutoboxedValues()
        {
            Matcher matcher = new EqualMatcher(1);

            Assert.IsTrue(matcher.Matches(1), "equal value");
            Assert.IsFalse(matcher.Matches(2), "other value");
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        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");
        }
Ejemplo n.º 7
0
        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");
        }
Ejemplo n.º 8
0
        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");
        }
Ejemplo n.º 9
0
        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");
        }
Ejemplo n.º 10
0
        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");
        }
Ejemplo n.º 11
0
        public void HasAReadableDescription()
        {
            Matcher matcher = new EqualMatcher("foo");

            AssertDescription.IsEqual(new PropertyMatcher("A", matcher), "property 'A' " + matcher);
        }
Ejemplo n.º 12
0
        public void HasAReadableDescription()
        {
            Matcher matcher = new EqualMatcher("foo");

            AssertDescription.IsEqual(new FieldMatcher("A", matcher), "field 'A' " + matcher);
        }
Ejemplo n.º 13
0
        public void Matches_should_apply_approximation()
        {
            var subj = new EqualMatcher <double>(5.0).OrClose(0.03);

            Assert.True(subj.Matches(5.02));
        }
Ejemplo n.º 14
0
        public void Matches_should_detect_strings_string_comparison()
        {
            var subj = new EqualMatcher <string>("A", StringComparer.OrdinalIgnoreCase);

            Assert.True(subj.Matches("a"));
        }
Ejemplo n.º 15
0
        public void Matches_should_detect_substrings_nominal()
        {
            var subj = new EqualMatcher <string>("a");

            Assert.True(subj.Matches("a"));
        }