Ejemplo n.º 1
0
        public static void Equality_None_ForReferenceT()
        {
            // Arrange
            var none    = Maybe <AnyT> .None;
            var same    = Maybe <AnyT> .None;
            var notSame = Maybe.SomeOrNone(AnyT.Value);

            // Act & Assert
            Assert.True(none == same);
            Assert.True(same == none);
            Assert.False(none == notSame);
            Assert.False(notSame == none);

            Assert.False(none != same);
            Assert.False(same != none);
            Assert.True(none != notSame);
            Assert.True(notSame != none);

            Assert.True(none.Equals(none));
            Assert.True(none.Equals(same));
            Assert.True(same.Equals(none));
            Assert.False(none.Equals(notSame));
            Assert.False(notSame.Equals(none));

            Assert.True(none.Equals((object)same));
            Assert.False(none.Equals((object)notSame));

            Assert.False(none.Equals(null));
            Assert.False(none.Equals(new object()));
        }
Ejemplo n.º 2
0
            public static void Equals_Some_ForReferenceT_WithCustomComparer()
            {
                // Arrange
                IStructuralEquatable anagram = Maybe.SomeOrNone(Anagram);
                var margana = Maybe.SomeOrNone(Margana);
                var other   = Maybe.SomeOrNone("XXX");
                var none    = Maybe <string> .None;
                var cmp     = new AnagramEqualityComparer();

                // Act & Assert
                Assert.True(anagram.Equals(anagram));
                Assert.False(anagram.Equals(margana));
                Assert.False(anagram.Equals(other));
                Assert.False(anagram.Equals(none));
                Assert.False(anagram.Equals(new object()));

                Assert.True(anagram.Equals(anagram, cmp));
                Assert.True(anagram.Equals(margana, cmp));
                Assert.False(anagram.Equals(other, cmp));
                Assert.False(anagram.Equals(none, cmp));
                Assert.False(anagram.Equals(new object(), cmp));
                Assert.False(anagram.Equals(null, cmp));

                // REVIEW: very odd, after Equals(null), we must use !.
                Assert.False(anagram.Equals(null));
            }
Ejemplo n.º 3
0
        public static void Comparable_Some_WithSome_AndEqual_ForNotComparable()
        {
            // Arrange
            var         anyT = AnyT.Value;
            IComparable x    = Maybe.SomeOrNone(anyT);
            var         y    = Maybe.SomeOrNone(anyT);

            // Act & Assert
            Assert.Equal(0, x.CompareTo(y));
        }
Ejemplo n.º 4
0
            public static void Comparable_Some_WithSome_AndEqual_ForNotComparable()
            {
                // Arrange
                var cmp  = Comparer <AnyT> .Default;
                var anyT = AnyT.Value;
                IStructuralComparable x = Maybe.SomeOrNone(anyT);
                var y = Maybe.SomeOrNone(anyT);

                // Act & Assert
                Assert.Equal(0, x.CompareTo(y, cmp));
            }
Ejemplo n.º 5
0
        public static void OpComparison_Some_Some_WhenEqual_ForNotComparable()
        {
            // Arrange
            var anyT = AnyT.Value;
            var x    = Maybe.SomeOrNone(anyT);
            var y    = Maybe.SomeOrNone(anyT);

            // Act & Assert
            Assert.False(x < y);
            Assert.True(x <= y);
            Assert.False(x > y);
            Assert.True(x >= y);
        }
Ejemplo n.º 6
0
            public static void Equals_None_ForReferenceT()
            {
                // Arrange
                IStructuralEquatable none = Maybe <AnyT> .None;
                var same = Maybe <AnyT> .None;
                var some = Maybe.SomeOrNone(AnyT.Value);
                var cmp  = EqualityComparer <AnyT> .Default;

                // Act & Assert
                Assert.False(none.Equals(null, cmp));
                Assert.False(none.Equals(new object(), cmp));

                Assert.True(none.Equals(none, cmp));
                Assert.True(none.Equals(same, cmp));

                Assert.False(none.Equals(some, cmp));
            }
Ejemplo n.º 7
0
            public static void Equals_Some_ForReferenceT_WithDefaultComparer()
            {
                // Arrange
                var anyT = AnyT.Value;
                IStructuralEquatable some = Maybe.SomeOrNone(anyT);
                var same    = Maybe.SomeOrNone(anyT);
                var notSame = Maybe.SomeOrNone(AnyT.Value);
                var none    = Maybe <AnyT> .None;
                var cmp     = EqualityComparer <AnyT> .Default;

                // Act & Assert
                Assert.False(some.Equals(null, cmp));
                Assert.False(some.Equals(new object(), cmp));

                Assert.True(some.Equals(some, cmp));
                Assert.True(some.Equals(same, cmp));
                Assert.False(some.Equals(notSame, cmp));

                Assert.False(some.Equals(none, cmp));
            }
Ejemplo n.º 8
0
 static Maybe <Maybe <T> > __ <T>(T x) where T : struct => Maybe.Some(Maybe.SomeOrNone((T?)x));