コード例 #1
0
        public void NormalComparer()
        {
            var original = StringComparer.Ordinal;
            var subject  = new ReverseComparer <string>(original);

            Assert.AreEqual(original.Compare("x", "y"), subject.Compare("y", "x"));
            Assert.AreEqual(0, subject.Compare("x", "x"));
        }
コード例 #2
0
ファイル: Compare.cs プロジェクト: GTuritto/ngenerics
        public void Simple()
        {
            var comparer = new ReverseComparer<int>();

            Assert.AreEqual(comparer.Compare(2, 3), 1);
            Assert.AreEqual(comparer.Compare(3, 2), -1);
            Assert.AreEqual(comparer.Compare(0, 0), 0);
            Assert.AreEqual(comparer.Compare(0, 1), 1);
            Assert.AreEqual(comparer.Compare(1, 0), -1);
        }
コード例 #3
0
ファイル: Compare.cs プロジェクト: vh-vahan/ngenerics
        public void Simple()
        {
            var comparer = new ReverseComparer <int>();

            Assert.AreEqual(comparer.Compare(2, 3), 1);
            Assert.AreEqual(comparer.Compare(3, 2), -1);
            Assert.AreEqual(comparer.Compare(0, 0), 0);
            Assert.AreEqual(comparer.Compare(0, 1), 1);
            Assert.AreEqual(comparer.Compare(1, 0), -1);
        }
コード例 #4
0
        public void ReverseComparerReturnsZeroWhenFirstItemEqualsSecondItem()
        {
            var comparer = new ReverseComparer <int>(Comparer <int> .Default);

            int first  = 1;
            int second = 1;

            int result = comparer.Compare(first, second);

            Assert.AreEqual(0, result);
        }
コード例 #5
0
        public void ReverseComparerReturnsPositiveOneWhenFirstItemIsLessThanSecondItem()
        {
            var comparer = new ReverseComparer <int>(Comparer <int> .Default);

            int first  = 1;
            int second = 2;

            int result = comparer.Compare(first, second);

            Assert.AreEqual(1, result);
        }
コード例 #6
0
        public void CustomComparer_LessThan()
        {
            // Arrange
            var comparer         = new CustomIntComparer();
            var reversedComparer = new ReverseComparer <int>(comparer);

            // Act-Assert (Precondition)
            Assert.Equal(-2, comparer.Compare(1, 2));

            // Act-Assert
            Assert.Equal(2, reversedComparer.Compare(1, 2));
        }
コード例 #7
0
        public void ReverseDefaultIntegerComparer_LessThan()
        {
            // Arrange
            var comparer         = Comparer <int> .Default;
            var reversedComparer = new ReverseComparer <int>(comparer);

            // Act-Assert (Precondition)
            Assert.Equal(-1, comparer.Compare(1, 2));

            // Act-Assert
            Assert.Equal(1, reversedComparer.Compare(1, 2));
        }
コード例 #8
0
        public void ReverseDefaultStringComparer_WithNull_GreaterThan()
        {
            // Arrange
            var comparer         = Comparer <string> .Default;
            var reversedComparer = new ReverseComparer <string>(comparer);

            // Act-Assert (Precondition)
            Assert.Equal(1, comparer.Compare("A", null));

            // Act-Assert
            Assert.Equal(-1, reversedComparer.Compare("A", null));
        }
コード例 #9
0
        public void ReverseDefaultStringComparer_WithNull_LessEqual()
        {
            // Arrange
            var comparer         = Comparer <string> .Default;
            var reversedComparer = new ReverseComparer <string>(comparer);

            // Act-Assert (Precondition)
            Assert.Equal(0, comparer.Compare(null, null));

            // Act-Assert
            Assert.Equal(0, reversedComparer.Compare(null, null));
        }
コード例 #10
0
        public void CustomComparer_Limits_GreaterThan()
        {
            // Arrange
            var comparer         = new CustomIntComparerLimits();
            var reversedComparer = new ReverseComparer <int>(comparer);

            // Act-Assert (Precondition)
            Assert.Equal(int.MaxValue, comparer.Compare(2, 1));

            // Act-Assert
            Assert.Equal(int.MinValue, reversedComparer.Compare(2, 1));
        }
コード例 #11
0
        public void Test_ReverseComparer_EqualTo()
        {
            // Arrange.
            IComparer <int> baseComparer    = Comparer <int> .Default;
            IComparer <int> reverseComparer = new ReverseComparer <int>(baseComparer);

            // Act.
            int result         = baseComparer.Compare(2, 2);
            int reversedResult = reverseComparer.Compare(2, 2);

            // Assert.
            Assert.Equal(result, reversedResult);
            Assert.Equal(0, result);
            Assert.Equal(0, reversedResult);
        }
コード例 #12
0
        public void Test_ReverseComparer_GreaterThan()
        {
            // Arrange.
            IComparer <int> baseComparer    = Comparer <int> .Default;
            IComparer <int> reverseComparer = new ReverseComparer <int>(baseComparer);

            // Act.
            int result         = baseComparer.Compare(2, 1);
            int reversedResult = reverseComparer.Compare(2, 1);

            // Assert.
            Assert.NotEqual(result, reversedResult);
            Assert.True(result > 0);
            Assert.True(reversedResult < 0);
        }