Example #1
0
        /// <summary>
        /// Gets if the two values are equal.
        /// </summary>
        /// <param name="other">
        /// The compared value.
        /// </param>
        /// <returns>
        /// returns <c>true</c> if
        ///
        /// The two values are both existing or missing
        /// and inner values are equal with the default comparer.
        /// </returns>
        public bool Equals(Opt <T> other)
        {
            if (!IsSome)
            {
                return(!other.IsSome);
            }

            return(other.IsSome && EqualityComparer <T> .Default.Equals(Value, other.Value));
        }
Example #2
0
        public void SomeHasValue()
        {
            var some1 = Opt.Some(1);

            some1.IsSome
            .Is(true);
            some1.Value
            .Is(1);
        }
Example #3
0
        public void NoneHasNoValue()
        {
            var none = Opt.None <int>();

            none.IsSome
            .Is(false);

            Assert.Throws <InvalidOperationException>(() =>
                                                      Opt.None <string>().Value
                                                      );
        }
Example #4
0
        /// <summary>
        /// Compare the two values.
        ///
        /// <c>None</c>s are lesser than <c>Some</c>s.
        /// </summary>
        public int CompareTo(Opt <T> other)
        {
            if (!IsSome)
            {
                return(other.IsSome ? 0 : 1);
            }

            if (!other.IsSome)
            {
                return(-1);
            }

            return(Comparer <T> .Default.Compare(Value, other.Value));
        }
Example #5
0
 public void ItMapsNoneToNestedSome()
 {
     Opt.AllowNull(Opt.None <int>())
     .Is(Opt.Some(Opt.None <int>()));
 }
Example #6
0
 public void ItMapsNonnullDefaultToSome()
 {
     Opt.AllowNull(default(int))
     .Is(Opt.Some(0));
 }
Example #7
0
 public void ItMapsNonnullToSome()
 {
     Opt.AllowNull("not null")
     .Is(Opt.Some("not null"));
 }
Example #8
0
 public void ItMapsNullStructToNone()
 {
     Opt.AllowNull((int?)null)
     .Is(Opt.None <int>());
 }
Example #9
0
 public void ItMapsNullReferenceToNone()
 {
     Opt.AllowNull((string)null)
     .Is(Opt.None <string>());
 }
Example #10
0
 public void SomeRejectsNull()
 {
     Assert.Throws <ArgumentNullException>(() =>
                                           Opt.Some((string)null)
                                           );
 }
Example #11
0
 public Field(Opt <T> defaultValue, int index)
 {
     DefaultValue = defaultValue;
     Index        = index;
 }