diff --git a/X10D.Tests/src/Linq/ByteTests.cs b/X10D.Tests/src/Linq/ByteTests.cs
index 50d2006..1c269b4 100644
--- a/X10D.Tests/src/Linq/ByteTests.cs
+++ b/X10D.Tests/src/Linq/ByteTests.cs
@@ -33,4 +33,64 @@ public class ByteTests
// Π_(i=1)^n (2i) will overflow at i=4 for byte
}
+
+ [TestMethod]
+ public void RangeTo_Byte_ShouldYieldCorrectValues()
+ {
+ const byte start = 1;
+ const byte end = 10;
+
+ byte current = 1;
+ foreach (byte value in start.RangeTo(end))
+ {
+ Assert.AreEqual(current++, value);
+ }
+
+ Assert.AreEqual(current, end);
+ }
+
+ [TestMethod]
+ public void RangeTo_Int16_ShouldYieldCorrectValues()
+ {
+ const byte start = 1;
+ const short end = 10;
+
+ short current = 1;
+ foreach (short value in start.RangeTo(end))
+ {
+ Assert.AreEqual(current++, value);
+ }
+
+ Assert.AreEqual(current, end);
+ }
+
+ [TestMethod]
+ public void RangeTo_Int32_ShouldYieldCorrectValues()
+ {
+ const byte start = 1;
+ const int end = 10;
+
+ int current = 1;
+ foreach (int value in start.RangeTo(end))
+ {
+ Assert.AreEqual(current++, value);
+ }
+
+ Assert.AreEqual(current, end);
+ }
+
+ [TestMethod]
+ public void RangeTo_Int64_ShouldYieldCorrectValues()
+ {
+ const byte start = 1;
+ const long end = 10;
+
+ long current = 1;
+ foreach (long value in start.RangeTo(end))
+ {
+ Assert.AreEqual(current++, value);
+ }
+
+ Assert.AreEqual(current, end);
+ }
}
diff --git a/X10D.Tests/src/Linq/Int16Tests.cs b/X10D.Tests/src/Linq/Int16Tests.cs
index 67e502e..c0f0636 100644
--- a/X10D.Tests/src/Linq/Int16Tests.cs
+++ b/X10D.Tests/src/Linq/Int16Tests.cs
@@ -37,4 +37,49 @@ public class Int16Tests
// Π_(i=1)^n (2i) will overflow at i=6 for short
}
+
+ [TestMethod]
+ public void RangeTo_Int16_ShouldYieldCorrectValues()
+ {
+ const short start = 1;
+ const short end = 10;
+
+ short current = 1;
+ foreach (short value in start.RangeTo(end))
+ {
+ Assert.AreEqual(current++, value);
+ }
+
+ Assert.AreEqual(current, end);
+ }
+
+ [TestMethod]
+ public void RangeTo_Int32_ShouldYieldCorrectValues()
+ {
+ const short start = 1;
+ const int end = 10;
+
+ int current = 1;
+ foreach (int value in start.RangeTo(end))
+ {
+ Assert.AreEqual(current++, value);
+ }
+
+ Assert.AreEqual(current, end);
+ }
+
+ [TestMethod]
+ public void RangeTo_Int64_ShouldYieldCorrectValues()
+ {
+ const short start = 1;
+ const long end = 10;
+
+ long current = 1;
+ foreach (long value in start.RangeTo(end))
+ {
+ Assert.AreEqual(current++, value);
+ }
+
+ Assert.AreEqual(current, end);
+ }
}
diff --git a/X10D.Tests/src/Linq/Int32Tests.cs b/X10D.Tests/src/Linq/Int32Tests.cs
index 33cc4ce..efc0870 100644
--- a/X10D.Tests/src/Linq/Int32Tests.cs
+++ b/X10D.Tests/src/Linq/Int32Tests.cs
@@ -40,4 +40,34 @@ public class Int32Tests
// Π_(i=1)^n (2i) will overflow at i=10 for int
}
+
+ [TestMethod]
+ public void RangeTo_Int32_ShouldYieldCorrectValues()
+ {
+ const int start = 1;
+ const int end = 10;
+
+ int current = 1;
+ foreach (int value in start.RangeTo(end))
+ {
+ Assert.AreEqual(current++, value);
+ }
+
+ Assert.AreEqual(current, end);
+ }
+
+ [TestMethod]
+ public void RangeTo_Int64_ShouldYieldCorrectValues()
+ {
+ const int start = 1;
+ const long end = 10;
+
+ long current = 1;
+ foreach (long value in start.RangeTo(end))
+ {
+ Assert.AreEqual(current++, value);
+ }
+
+ Assert.AreEqual(current, end);
+ }
}
diff --git a/X10D.Tests/src/Linq/Int64Tests.cs b/X10D.Tests/src/Linq/Int64Tests.cs
index 3e543ce..5535eeb 100644
--- a/X10D.Tests/src/Linq/Int64Tests.cs
+++ b/X10D.Tests/src/Linq/Int64Tests.cs
@@ -41,4 +41,19 @@ public class Int64Tests
Assert.AreEqual(185794560, Enumerable.Range(1, 9).Product(Double));
Assert.AreEqual(3715891200, Enumerable.Range(1, 10).Product(Double));
}
+
+ [TestMethod]
+ public void RangeTo_Int64_ShouldYieldCorrectValues()
+ {
+ const long start = 1;
+ const long end = 10;
+
+ long current = 1;
+ foreach (long value in start.RangeTo(end))
+ {
+ Assert.AreEqual(current++, value);
+ }
+
+ Assert.AreEqual(current, end);
+ }
}
diff --git a/X10D/src/Int16Extensions/Int16Extensions.cs b/X10D/src/Int16Extensions/Int16Extensions.cs
index 93ef82f..68999ac 100644
--- a/X10D/src/Int16Extensions/Int16Extensions.cs
+++ b/X10D/src/Int16Extensions/Int16Extensions.cs
@@ -7,86 +7,6 @@ namespace X10D;
///
public static class Int16Extensions
{
- ///
- /// Returns an enumerable collection of 16-bit signed integers that range from the current value to a specified value.
- ///
- /// The value of the first integer in the sequence.
- /// The value of the last integer in the sequence.
- ///
- ///
- /// An enumerable collection of 16-bit signed integers that range from to
- /// in ascending order if is less than than .
- ///
- /// -or-
- ///
- /// An enumerable collection of 16-bit signed integers that range from to
- /// in descending order if is greater than than
- /// .
- ///
- /// -or-
- ///
- /// An enumerable collection that contains a single value if is equal to
- /// .
- ///
- ///
- public static IEnumerable To(this short start, short end)
- {
- return start.To(end, 1);
- }
-
- ///
- /// Returns an enumerable collection of 16-bit signed integers that range from the current value to a specified value.
- ///
- /// The value of the first integer in the sequence.
- /// The value of the last integer in the sequence.
- /// The increment by which to step.
- ///
- ///
- /// An enumerable collection of 16-bit signed integers that range from to
- /// in ascending order if is less than than .
- ///
- /// -or-
- ///
- /// An enumerable collection of 16-bit signed integers that range from to
- /// in descending order if is greater than than
- /// .
- ///
- /// -or-
- ///
- /// An enumerable collection that contains a single value if is equal to
- /// .
- ///
- ///
- public static IEnumerable To(this short start, short end, short step)
- {
- if (step == 0)
- {
- throw new ArgumentOutOfRangeException(nameof(step), "Step cannot be zero.");
- }
-
- if (end == start)
- {
- yield return start;
- yield break;
- }
-
- if (step > 0 || start < end)
- {
- for (short i = start; i <= end; i += step)
- {
- yield return i;
- }
- }
- else
- {
- short absStep = System.Math.Abs(step);
- for (short i = start; i >= end; i -= absStep)
- {
- yield return i;
- }
- }
- }
-
///
/// Converts an integer value from network byte order to host byte order.
///
diff --git a/X10D/src/Int32Extensions/Int32Extensions.cs b/X10D/src/Int32Extensions/Int32Extensions.cs
index 61211b3..3109dea 100644
--- a/X10D/src/Int32Extensions/Int32Extensions.cs
+++ b/X10D/src/Int32Extensions/Int32Extensions.cs
@@ -70,86 +70,6 @@ public static class Int32Extensions
return ((float)value).DegreesToRadians();
}
- ///
- /// Returns an enumerable collection of 32-bit signed integers that range from the current value to a specified value.
- ///
- /// The value of the first integer in the sequence.
- /// The value of the last integer in the sequence.
- ///
- ///
- /// An enumerable collection of 32-bit signed integers that range from to
- /// in ascending order if is less than than .
- ///
- /// -or-
- ///
- /// An enumerable collection of 32-bit signed integers that range from to
- /// in descending order if is greater than than
- /// .
- ///
- /// -or-
- ///
- /// An enumerable collection that contains a single value if is equal to
- /// .
- ///
- ///
- public static IEnumerable To(this int start, int end)
- {
- return start.To(end, 1);
- }
-
- ///
- /// Returns an enumerable collection of 32-bit signed integers that range from the current value to a specified value.
- ///
- /// The value of the first integer in the sequence.
- /// The value of the last integer in the sequence.
- /// The increment by which to step.
- ///
- ///
- /// An enumerable collection of 32-bit signed integers that range from to
- /// in ascending order if is less than than .
- ///
- /// -or-
- ///
- /// An enumerable collection of 32-bit signed integers that range from to
- /// in descending order if is greater than than
- /// .
- ///
- /// -or-
- ///
- /// An enumerable collection that contains a single value if is equal to
- /// .
- ///
- ///
- public static IEnumerable To(this int start, int end, int step)
- {
- if (step == 0)
- {
- throw new ArgumentOutOfRangeException(nameof(step), "Step cannot be zero.");
- }
-
- if (end == start)
- {
- yield return start;
- yield break;
- }
-
- if (step > 0 || start < end)
- {
- for (int i = start; i <= end; i += step)
- {
- yield return i;
- }
- }
- else
- {
- int absStep = System.Math.Abs(step);
- for (int i = start; i >= end; i -= absStep)
- {
- yield return i;
- }
- }
- }
-
///
/// Converts an integer value from network byte order to host byte order.
///
diff --git a/X10D/src/Int64Extensions/Int64Extensions.cs b/X10D/src/Int64Extensions/Int64Extensions.cs
index 1e1de6f..b6463cd 100644
--- a/X10D/src/Int64Extensions/Int64Extensions.cs
+++ b/X10D/src/Int64Extensions/Int64Extensions.cs
@@ -51,86 +51,6 @@ public static class Int64Extensions
return persistence;
}
- ///
- /// Returns an enumerable collection of 64-bit signed integers that range from the current value to a specified value.
- ///
- /// The value of the first integer in the sequence.
- /// The value of the last integer in the sequence.
- ///
- ///
- /// An enumerable collection of 64-bit signed integers that range from to
- /// in ascending order if is less than than .
- ///
- /// -or-
- ///
- /// An enumerable collection of 64-bit signed integers that range from to
- /// in descending order if is greater than than
- /// .
- ///
- /// -or-
- ///
- /// An enumerable collection that contains a single value if is equal to
- /// .
- ///
- ///
- public static IEnumerable To(this long start, long end)
- {
- return start.To(end, 1);
- }
-
- ///
- /// Returns an enumerable collection of 64-bit signed integers that range from the current value to a specified value.
- ///
- /// The value of the first integer in the sequence.
- /// The value of the last integer in the sequence.
- /// The increment by which to step.
- ///
- ///
- /// An enumerable collection of 64-bit signed integers that range from to
- /// in ascending order if is less than than .
- ///
- /// -or-
- ///
- /// An enumerable collection of 64-bit signed integers that range from to
- /// in descending order if is greater than than
- /// .
- ///
- /// -or-
- ///
- /// An enumerable collection that contains a single value if is equal to
- /// .
- ///
- ///
- public static IEnumerable To(this long start, long end, long step)
- {
- if (step == 0)
- {
- throw new ArgumentOutOfRangeException(nameof(step), "Step cannot be zero.");
- }
-
- if (end == start)
- {
- yield return start;
- yield break;
- }
-
- if (step > 0 || start < end)
- {
- for (long i = start; i <= end; i += step)
- {
- yield return i;
- }
- }
- else
- {
- long absStep = System.Math.Abs(step);
- for (long i = start; i >= end; i -= absStep)
- {
- yield return i;
- }
- }
- }
-
///
/// Converts an integer value from network byte order to host byte order.
///
diff --git a/X10D/src/Linq/ByteExtensions.cs b/X10D/src/Linq/ByteExtensions.cs
index 2f183cd..0164d1f 100644
--- a/X10D/src/Linq/ByteExtensions.cs
+++ b/X10D/src/Linq/ByteExtensions.cs
@@ -52,4 +52,80 @@ public static class ByteExtensions
{
return source.Select(selector).Product();
}
+
+ ///
+ /// Returns an enumerable sequence of 8-bit integers ranging from the current value to a specified value.
+ ///
+ /// The starting value of the sequence.
+ /// The ending value of the sequence.
+ ///
+ /// An enumerable collection of 8-bit integers, ranging from to .
+ ///
+ public static IEnumerable RangeTo(this byte value, byte end)
+ {
+ byte start = System.Math.Min(value, end);
+ end = System.Math.Max(value, end);
+
+ for (byte current = start; current < end; current++)
+ {
+ yield return current;
+ }
+ }
+
+ ///
+ /// Returns an enumerable sequence of 16-bit integers ranging from the current value to a specified value.
+ ///
+ /// The starting value of the sequence.
+ /// The ending value of the sequence.
+ ///
+ /// An enumerable collection of 16-bit integers, ranging from to .
+ ///
+ public static IEnumerable RangeTo(this byte value, short end)
+ {
+ short start = System.Math.Min(value, end);
+ end = System.Math.Max(value, end);
+
+ for (short current = start; current < end; current++)
+ {
+ yield return current;
+ }
+ }
+
+ ///
+ /// Returns an enumerable sequence of 32-bit integers ranging from the current value to a specified value.
+ ///
+ /// The starting value of the sequence.
+ /// The ending value of the sequence.
+ ///
+ /// An enumerable collection of 32-bit integers, ranging from to .
+ ///
+ public static IEnumerable RangeTo(this byte value, int end)
+ {
+ int start = System.Math.Min(value, end);
+ end = System.Math.Max(value, end);
+
+ for (int current = start; current < end; current++)
+ {
+ yield return current;
+ }
+ }
+
+ ///
+ /// Returns an enumerable sequence of 64-bit integers ranging from the current value to a specified value.
+ ///
+ /// The starting value of the sequence.
+ /// The ending value of the sequence.
+ ///
+ /// An enumerable collection of 64-bit integers, ranging from to .
+ ///
+ public static IEnumerable RangeTo(this byte value, long end)
+ {
+ long start = System.Math.Min(value, end);
+ end = System.Math.Max(value, end);
+
+ for (long current = start; current < end; current++)
+ {
+ yield return current;
+ }
+ }
}
diff --git a/X10D/src/Linq/Int16Extensions.cs b/X10D/src/Linq/Int16Extensions.cs
index e18d492..e6b78d1 100644
--- a/X10D/src/Linq/Int16Extensions.cs
+++ b/X10D/src/Linq/Int16Extensions.cs
@@ -52,4 +52,61 @@ public static class Int16Extensions
{
return source.Select(selector).Product();
}
+
+ ///
+ /// Returns an enumerable sequence of 16-bit integers ranging from the current value to a specified value.
+ ///
+ /// The starting value of the sequence.
+ /// The ending value of the sequence.
+ ///
+ /// An enumerable collection of 16-bit integers, ranging from to .
+ ///
+ public static IEnumerable RangeTo(this short value, short end)
+ {
+ short start = System.Math.Min(value, end);
+ end = System.Math.Max(value, end);
+
+ for (short current = start; current < end; current++)
+ {
+ yield return current;
+ }
+ }
+
+ ///
+ /// Returns an enumerable sequence of 32-bit integers ranging from the current value to a specified value.
+ ///
+ /// The starting value of the sequence.
+ /// The ending value of the sequence.
+ ///
+ /// An enumerable collection of 32-bit integers, ranging from to .
+ ///
+ public static IEnumerable RangeTo(this short value, int end)
+ {
+ int start = System.Math.Min(value, end);
+ end = System.Math.Max(value, end);
+
+ for (int current = start; current < end; current++)
+ {
+ yield return current;
+ }
+ }
+
+ ///
+ /// Returns an enumerable sequence of 64-bit integers ranging from the current value to a specified value.
+ ///
+ /// The starting value of the sequence.
+ /// The ending value of the sequence.
+ ///
+ /// An enumerable collection of 64-bit integers, ranging from to .
+ ///
+ public static IEnumerable RangeTo(this short value, long end)
+ {
+ long start = System.Math.Min(value, end);
+ end = System.Math.Max(value, end);
+
+ for (long current = start; current < end; current++)
+ {
+ yield return current;
+ }
+ }
}
diff --git a/X10D/src/Linq/Int32Extensions.cs b/X10D/src/Linq/Int32Extensions.cs
index b8f6692..5898c6d 100644
--- a/X10D/src/Linq/Int32Extensions.cs
+++ b/X10D/src/Linq/Int32Extensions.cs
@@ -52,4 +52,42 @@ public static class Int32Extensions
{
return source.Select(selector).Product();
}
+
+ ///
+ /// Returns an enumerable sequence of 32-bit integers ranging from the current value to a specified value.
+ ///
+ /// The starting value of the sequence.
+ /// The ending value of the sequence.
+ ///
+ /// An enumerable collection of 32-bit integers, ranging from to .
+ ///
+ public static IEnumerable RangeTo(this int value, int end)
+ {
+ int start = System.Math.Min(value, end);
+ end = System.Math.Max(value, end);
+
+ for (int current = start; current < end; current++)
+ {
+ yield return current;
+ }
+ }
+
+ ///
+ /// Returns an enumerable sequence of 64-bit integers ranging from the current value to a specified value.
+ ///
+ /// The starting value of the sequence.
+ /// The ending value of the sequence.
+ ///
+ /// An enumerable collection of 64-bit integers, ranging from to .
+ ///
+ public static IEnumerable RangeTo(this int value, long end)
+ {
+ long start = System.Math.Min(value, end);
+ end = System.Math.Max(value, end);
+
+ for (long current = start; current < end; current++)
+ {
+ yield return current;
+ }
+ }
}
diff --git a/X10D/src/Linq/Int64Extensions.cs b/X10D/src/Linq/Int64Extensions.cs
index df1b6c1..89e839c 100644
--- a/X10D/src/Linq/Int64Extensions.cs
+++ b/X10D/src/Linq/Int64Extensions.cs
@@ -52,4 +52,23 @@ public static class Int64Extensions
{
return source.Select(selector).Product();
}
+
+ ///
+ /// Returns an enumerable sequence of 64-bit integers ranging from the current value to a specified value.
+ ///
+ /// The starting value of the sequence.
+ /// The ending value of the sequence.
+ ///
+ /// An enumerable collection of 64-bit integers, ranging from to .
+ ///
+ public static IEnumerable RangeTo(this long value, long end)
+ {
+ long start = System.Math.Min(value, end);
+ end = System.Math.Max(value, end);
+
+ for (long current = start; current < end; current++)
+ {
+ yield return current;
+ }
+ }
}