/// <summary>
        /// Adds <see cref="item"/> to list.
        /// Applies <see cref="item"/> if <see cref="IMutationEvent{T}"/>
        /// or  <see cref="item"/> if <see cref="IOrderedEvent{TKey, TOrder}.Order"/> <see cref="CompareUtilities.GreaterOrEqualTo"/> <see cref="MaxOrder"/>.
        /// </summary>
        /// <param name="value"></param>
        /// <param name="item"></param>
        /// <returns>Wether <see cref="item"/> is applied.</returns>
        public override bool AddAndApply(IEvent <T, TKey> item, T value)
        {
            Add(item);

            if (!(item is IOrderedEvent <TKey, TOrder>) ||
                item is IMutationEvent <T, TKey> ||
                (item is IOrderedEvent <TKey, TOrder> orderedEvent && CompareUtilities.GreaterOrEqualTo(orderedEvent.Order, MaxOrder)))
            {
                item.Apply(value);
                return(true);
            }

            return(false);
        }
Exemple #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DetectionRange"/> class.
        /// </summary>
        /// <param name="low"></param>
        /// <param name="normal"></param>
        /// <param name="high"></param>
        /// <exception cref="ArgumentException">If <see cref=low"/> greater than <see cref="normal"/>.</exception>
        /// <exception cref="ArgumentException">If <see cref="high"/> smaller than <see cref="normal"/>.</exception>
        public ValueRange(TValue low, TValue normal, TValue high)
        {
            if (!CompareUtilities.SmallerOrEqualTo(low, normal))
            {
                throw new ArgumentException($"{nameof(low)} must be smaller or equal to {normal}.", nameof(low));
            }

            if (!CompareUtilities.GreaterOrEqualTo(high, normal))
            {
                throw new ArgumentException($"{nameof(high)} must be smaller or equal to {normal}.", nameof(high));
            }

            Low    = low;
            Normal = normal;
            High   = high;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="DetectionRange"/> class.
        /// </summary>
        /// <param name="maxDetectionLow"></param>
        /// <param name="low"></param>
        /// <param name="normal"></param>
        /// <param name="high"></param>
        /// <param name="maxDetectionHigh"></param>
        /// <exception cref="ArgumentException">If <see cref="MaxDetectionLow"/> greater than <see cref="low"/>.</exception>
        /// <exception cref="ArgumentException">If <see cref="MaxDetectionHigh"/> smaller than <see cref="high"/>.</exception>
        public DetectionRange(TValue maxDetectionLow, TValue low, TValue normal, TValue high, TValue maxDetectionHigh)
            : base(low, normal, high)
        {
            if (!CompareUtilities.SmallerOrEqualTo(maxDetectionLow, low))
            {
                throw new ArgumentException($"{nameof(maxDetectionLow)} must be smaller or equal to {low}.", nameof(maxDetectionLow));
            }

            if (!CompareUtilities.GreaterOrEqualTo(maxDetectionHigh, high))
            {
                throw new ArgumentException($"{nameof(maxDetectionHigh)} must be smaller or equal to {high}.", nameof(maxDetectionHigh));
            }

            MaxDetectionLow  = maxDetectionLow;
            MaxDetectionHigh = maxDetectionHigh;
        }
Exemple #4
0
 public void GreaterOrEqualTo_When_Double(int value, int compare, bool expected)
 {
     Assert.Equal(expected, CompareUtilities.GreaterOrEqualTo(RangeFactory.ToTestDouble(value), RangeFactory.ToTestDouble(compare)));
 }
Exemple #5
0
 public void GreaterOrEqualTo_When_Int(int value, int compare, bool expected)
 {
     Assert.Equal(expected, CompareUtilities.GreaterOrEqualTo(value, compare));
 }
 /// <summary>
 /// Does the <see cref="range"/> equal or exceed the limits of <see cref="compare"/>
 /// Is <see cref="range.From"/> smaller or equal to <see cref="compare.From"/>
 /// Is <see cref="range.Till"/> greater or equal to <see cref="compare.Till"/>
 /// </summary>
 /// <typeparam name="TValue"></typeparam>
 /// <param name="range"></param>
 /// <param name="compare"></param>
 /// <returns></returns>
 public static bool Ecapsulates <TValue>(this IRange <TValue> range, IRange <TValue> compare)
     where TValue : IComparable <TValue>
 {
     return(CompareUtilities.SmallerOrEqualTo(range.From, compare.From) && CompareUtilities.GreaterOrEqualTo(range.Till, compare.Till));
 }