Esempio n. 1
0
    static string ExpandRange(SingleRange range)
    {
        char first = range._first;
        char last  = range._last;

        return(String.Concat(Enumerable.Range(first, last - first + 1).Select(i => (char)i)));
    }
Esempio n. 2
0
        private static SingleRange GetEquallyDividedSubRange(SingleRange singleRange, int numSubRanges, int mySubRangeIndex)
        {
            var  rangeSize = singleRange.RangeSize();
            uint portion   = (uint)(rangeSize / numSubRanges);
            uint remainder = (uint)(rangeSize - portion * numSubRanges);
            uint start     = singleRange.Begin;

            for (int i = 0; i < numSubRanges; i++)
            {
                // (Begin, End]
                uint end = (unchecked (start + portion));
                // I want it to overflow on purpose. It will do the right thing.
                if (remainder > 0)
                {
                    end++;
                    remainder--;
                }
                if (i == mySubRangeIndex)
                {
                    return(new SingleRange(start, end));
                }
                start = end; // nextStart
            }
            throw new ArgumentException(nameof(mySubRangeIndex));
        }
Esempio n. 3
0
 public void Range_MinGreaterThanMax()
 {
     // Act & Assert
     Assert.Throws(typeof(ArgumentException),
                   // ReSharper disable once ObjectCreationAsStatement
                   () => SingleRange.Range(20, 10));
 }
Esempio n. 4
0
            public static SingleRange Intersect(SingleRange a, SingleRange b)
            {
                BoundValue <T> newLower = a.lower < b.lower ? b.lower : a.lower;
                BoundValue <T> newUpper = a.upper < b.upper ? a.upper : b.upper;

                return(new SingleRange(newLower, newUpper));
            }
Esempio n. 5
0
        public void Range_MinEqualToMax()
        {
            // Act
            var range = SingleRange.Range(10, 10);

            // Assert
            AssertChunks(range, 10, 10);
        }
Esempio n. 6
0
        public void Range_MinLowerThanMax()
        {
            // Act
            var range = SingleRange.Range(10, 20);

            // Assert
            AssertChunks(range, 10, 20);
        }
        /// <summary>
        ///		Extension method that allows for <see cref="NonIntegralRangeBase{TIntegralType}.Constrain"/>
        ///		to be called on a <see cref="Single"/> subject with the range and exclusivity passed as a
        ///		parameter, rather than on the <see cref="NonIntegralRangeBase{TIntegralType}"/> object
        ///		with a <see cref="Single"/> parameter.
        /// </summary>
        /// <param name="this">
        ///		The subject <see cref="Single"/> value in which to check against the <paramref name="range"/>
        ///		parameter to constrain a value within a range with an implicit inclusive comparison mode.
        /// </param>
        /// <param name="range">
        ///		An instance of the type <see cref="SingleRange"/>, describing a range of numeric values in
        ///		which the <paramref name="this"/> subject is to be compared against.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///		Thrown when the specified <paramref name="range"/> is <see langword="null"/>.
        ///	</exception>
        /// <returns>
        ///		A <see cref="Single"/> value that is the <paramref name="this"/> subject value adjusted to
        ///		force the range of possible values to be within the provided <paramref cref="range"/>
        ///		parameter, using <see cref="EndpointExclusivity.Inclusive"/> as the comparison mode.
        /// </returns>
        public static Single Constrain(
            this Single @this,
            [NotNull] SingleRange range)
        {
            range.IsNotNull(nameof(range));

            return(range
                   .Constrain(
                       @this));
        }
        /// <summary>
        ///		Extension method that allows for <see cref="NonIntegralRangeBase{TIntegralType}.IsNotWithin"/>
        ///		to be called on a <see cref="Single"/> subject with the range and exclusivity passed as a
        ///		parameter, rather than on the <see cref="NonIntegralRangeBase{TIntegralType}"/> object
        ///		with a <see cref="Single"/> parameter.
        /// </summary>
        /// <param name="this">
        ///		The subject <see cref="Single"/> value in which to check against the <paramref name="range"/>
        ///		parameter to determine whether it is within the range, taking into account the exclusivity.
        /// </param>
        /// <param name="range">
        ///		An instance of the type <see cref="SingleRange"/>, describing a range of numeric values in
        ///		which the <paramref name="this"/> subject is to be compared against.
        /// </param>
        /// <param name="exclusivity">
        ///		A value indicating whether to perform the upper and lower bounds comparisons including
        ///		the range's Minimum and Maximum bounds, or to exclude them. This parameter is optional,
        ///		and the default value is <see cref="EndpointExclusivity.Inclusive"/>.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///		Thrown when the specified <paramref name="range"/> is <see langword="null"/>.
        ///	</exception>
        /// <returns>
        ///		A <see cref="Single"/> value indicating whether or not the <paramref name="this"/> subject
        ///		is within the provided <paramref cref="range"/> parameter, taking into account the
        ///		<see cref="EndpointExclusivity"/> mode via the <paramref name="exclusivity"/> parameter.
        ///		This comparison is the logical inverse of the <see cref="IsNotWithin"/> extension method.
        /// </returns>
        public static bool IsNotWithin(
            this Single @this,
            [NotNull] SingleRange range,
            EndpointExclusivity exclusivity = EndpointExclusivity.Inclusive)
        {
            range.IsNotNull(nameof(range));

            return(range
                   .IsNotWithin(
                       @this,
                       exclusivity));
        }
Esempio n. 9
0
        public void AddChunk_Error()
        {
            // Arrange
            var range = SingleRange.Range(10, 20);

            // Assume
            AssertChunks(range, 10, 20);

            // Act & Assert
            Assert.Throws(typeof(ArgumentException),
                          // ReSharper disable once ObjectCreationAsStatement
                          () => range.Range(20, 10));
        }
Esempio n. 10
0
        public void AddChunk_ImmediatelyBeforeMin1()
        {
            var range = SingleRange.Range(10, 20);

            // Assume
            AssertChunks(range, 10, 20);

            // Act
            range.Range(_Before10, _Before10);

            // Assert
            AssertChunks(range, _Before10, 20);
        }
Esempio n. 11
0
        public void AddChunk_AfterMaxInfinity()
        {
            // Arrange
            var range = SingleRange.Range(10, 20);

            // Assume
            AssertChunks(range, 10, 20);

            // Act
            range.Range(30, SingleRange.MaxValue);

            // Assert
            AssertChunks(range, 10, 20, 30, SingleRange.MaxValue);
        }
Esempio n. 12
0
        public void AddChunk_AfterMax()
        {
            // Arrange
            var range = SingleRange.Range(10, 20);

            // Assume
            AssertChunks(range, 10, 20);

            // Act
            range.Range(30, 40);

            // Assert
            AssertChunks(range, 10, 20, 30, 40);
        }
Esempio n. 13
0
        public void AddChunk_MaxImmediatelyAfterMax()
        {
            // Arrange
            var range = SingleRange.Range(10, 20);

            // Assume
            AssertChunks(range, 10, 20);

            // Act
            range.Range(15, _After20);

            // Assert
            AssertChunks(range, 10, _After20);
        }
Esempio n. 14
0
        public void AddChunk_ContainingMax()
        {
            // Arrange
            var range = SingleRange.Range(10, 20);

            // Assume
            AssertChunks(range, 10, 20);

            // Act
            range.Range(12, 25);

            // Assert
            AssertChunks(range, 10, 25);
        }
Esempio n. 15
0
        public void AddChunk_BetweenMinMax()
        {
            // Arrange
            var range = SingleRange.Range(10, 20);

            // Assume
            AssertChunks(range, 10, 20);

            // Act
            range.Range(12, 14);

            // Assert
            AssertChunks(range, 10, 20);
        }
Esempio n. 16
0
        public void AddChunk_MinImmediatelyBeforeMin()
        {
            // Arrange
            var range = SingleRange.Range(10, 20);

            // Assume
            AssertChunks(range, 10, 20);

            // Act
            range.Range(_Before10, 15);

            // Assert
            AssertChunks(range, _Before10, 20);
        }
Esempio n. 17
0
        public void AddChunk_BeforeMin()
        {
            // Arrange
            var range = SingleRange.Range(10, 20);

            // Assume
            AssertChunks(range, 10, 20);

            // Act
            range.Range(5, 8);

            // Assert
            AssertChunks(range, 5, 8, 10, 20);
        }
Esempio n. 18
0
        public void AddChunk_InfinityBeforeMin()
        {
            // Arrange
            var range = SingleRange.Range(10, 20);

            // Assume
            AssertChunks(range, 10, 20);

            // Act
            range.Range(SingleRange.MinValue, 8);

            // Assert
            AssertChunks(range, SingleRange.MinValue, 8, 10, 20);
        }
Esempio n. 19
0
        public void AddChunk_ContainingMin()
        {
            // Arrange
            var range = SingleRange.Range(10, 20);

            // Assume
            AssertChunks(range, 10, 20);

            // Act
            range.Range(5, 14);

            // Assert
            AssertChunks(range, 5, 20);
        }
        /// <summary>
        ///		Extension method that performs a transformation on the <see cref="Single"/> subject using
        ///		linear mapping to re-map from the provided initial range <paramref name="startRange"/>
        ///		to the target range <paramref name="endRange"/>.
        /// </summary>
        /// <param name="this">
        ///		The subject <see cref="Single"/> to perform the linear map range re-mapping upon.
        /// </param>
        /// <param name="startRange">
        ///		An instance of the type <see cref="SingleRange"/>, describing a range of numeric values in
        ///		which the linear re-mapping uses as the initial range of the subject.
        /// </param>
        /// <param name="endRange">
        ///		An instance of the type <see cref="SingleRange"/>, describing a range of numeric values in
        ///		which the linear re-mapping uses as the target range of the return value.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///		Thrown when either the <paramref name="startRange"/> or the <paramref name="endRange"/>
        ///		parameters are equal to <see langword="null"/>.
        ///	</exception>
        /// <returns>
        ///		A <see cref="Single"/> value that has been linearly mapped to the <paramref name="startRange"/>
        ///		parameter and re-mapped to the <paramref name="endRange"/> parameter.
        /// </returns>
        public static Single LinearMap(
            this Single @this,
            [NotNull] SingleRange startRange,
            [NotNull] SingleRange endRange)
        {
            startRange.IsNotNull(nameof(startRange));
            endRange.IsNotNull(nameof(endRange));

            return((
                       (@this - startRange.Minimum) *
                       (endRange.Maximum - endRange.Minimum) /
                       (startRange.Maximum - startRange.Minimum) +
                       endRange.Minimum)
                   .To <Single>());
        }
Esempio n. 21
0
        public void AddChunk2_ContainingMinMax1_ImmediatelyBeforeMin2()
        {
            // Arrange
            var range = SingleRange.Range(10, 20);

            range.Range(30, 40);

            // Assume
            AssertChunks(range, 10, 20, 30, 40);

            // Act
            range.Range(5, _Before30);

            // Assert
            AssertChunks(range, 5, 40);
        }
Esempio n. 22
0
        public void AddChunkThatCompleteBoth()
        {
            // Arrange
            var range = SingleRange.Range(1, SingleRange.MaxValue);

            range.Range(SingleRange.MinValue, -1);

            // Assume
            AssertChunks(range, SingleRange.MinValue, -1, 1, SingleRange.MaxValue);

            // Act
            range.Range(BitConverterHelper.Next(-1F), BitConverterHelper.Previous(1F));

            // Assert
            AssertChunks(range, SingleRange.MinValue, SingleRange.MaxValue);
        }
Esempio n. 23
0
        public void AddChunk2_ImmediatelyAfterMax2_Infinity()
        {
            // Arrange
            var range = SingleRange.Range(10, 20);

            range.Range(30, 40);

            // Assume
            AssertChunks(range, 10, 20, 30, 40);

            // Act
            range.Range(_After40, SingleRange.MaxValue);

            // Assert
            AssertChunks(range, 10, 20, 30, SingleRange.MaxValue);
        }
Esempio n. 24
0
        public void AddChunk2_BetweenMinMax2_Infinity()
        {
            // Arrange
            var range = SingleRange.Range(10, 20);

            range.Range(30, 40);

            // Assume
            AssertChunks(range, 10, 20, 30, 40);

            // Act
            range.Range(34, SingleRange.MaxValue);

            // Assert
            AssertChunks(range, 10, 20, 30, SingleRange.MaxValue);
        }
Esempio n. 25
0
        public void AddChunk2_BetweenMinMax2_AfterMax2()
        {
            // Arrange
            var range = SingleRange.Range(10, 20);

            range.Range(30, 40);

            // Assume
            AssertChunks(range, 10, 20, 30, 40);

            // Act
            range.Range(34, 46);

            // Assert
            AssertChunks(range, 10, 20, 30, 46);
        }
Esempio n. 26
0
        public void AddChunk2_ImmediatelyBeforeMin1()
        {
            // Arrange
            var range = SingleRange.Range(10, 20);

            range.Range(30, 40);

            // Assume
            AssertChunks(range, 10, 20, 30, 40);

            // Act
            range.Range(5, _Before10);

            // Assert
            AssertChunks(range, 5, 20, 30, 40);
        }
Esempio n. 27
0
        public void AddChunk2_AfterMax1_ImmediatelyBeforeMin2()
        {
            // Arrange
            var range = SingleRange.Range(10, 20);

            range.Range(30, 40);

            // Assume
            AssertChunks(range, 10, 20, 30, 40);

            // Act
            range.Range(23, _Before30);

            // Assert
            AssertChunks(range, 10, 20, 23, 40);
        }
Esempio n. 28
0
        public void AddChunk2_ImmediatelyAfterMax1_AfterMax2()
        {
            // Arrange
            var range = SingleRange.Range(10, 20);

            range.Range(30, 40);

            // Assume
            AssertChunks(range, 10, 20, 30, 40);

            // Act
            range.Range(_After20, 45);

            // Assert
            AssertChunks(range, 10, 45);
        }
Esempio n. 29
0
        public void AddChunk2_ContainingMax1_ContainingMinMax2()
        {
            // Arrange
            var range = SingleRange.Range(10, 20);

            range.Range(30, 40);

            // Assume
            AssertChunks(range, 10, 20, 30, 40);

            // Act
            range.Range(15, 42);

            // Assert
            AssertChunks(range, 10, 42);
        }
Esempio n. 30
0
        public void AddChunk2_ContainingMinMax1_Infinity()
        {
            // Arrange
            var range = SingleRange.Range(10, 20);

            range.Range(30, 40);

            // Assume
            AssertChunks(range, 10, 20, 30, 40);

            // Act
            range.Range(5, SingleRange.MaxValue);

            // Assert
            AssertChunks(range, 5, SingleRange.MaxValue);
        }