Assert.Empty(actual);
}
+
+ [Fact]
+ public void CircularCountUp_Test()
+ {
+ var actual = MyCommon.CircularCountUp(length: 6, startIndex: 3);
+
+ Assert.Equal(new[] { 3, 4, 5, 0, 1, 2 }, actual);
+ }
+
+ [Fact]
+ public void CircularCountUp_StartFromZeroTest()
+ {
+ var actual = MyCommon.CircularCountUp(length: 6, startIndex: 0);
+
+ Assert.Equal(new[] { 0, 1, 2, 3, 4, 5 }, actual);
+ }
+
+ [Fact]
+ public void CircularCountDown_Test()
+ {
+ var actual = MyCommon.CircularCountDown(length: 6, startIndex: 3);
+
+ Assert.Equal(new[] { 3, 2, 1, 0, 5, 4 }, actual);
+ }
+
+ [Fact]
+ public void CircularCountDown_StartFromLastIndexTest()
+ {
+ var actual = MyCommon.CircularCountDown(length: 6, startIndex: 5);
+
+ Assert.Equal(new[] { 5, 4, 3, 2, 1, 0 }, actual);
+ }
}
}
if (this.AllCount == 0)
yield break;
- var searchIndices = Enumerable.Empty<int>();
+ IEnumerable<int> searchIndices;
if (!reverse)
- {
- // startindex ...末尾
- if (startIndex != this.AllCount - 1)
- searchIndices = MyCommon.CountUp(startIndex, this.AllCount - 1);
-
- // 先頭 ... (startIndex - 1)
- if (startIndex != 0)
- searchIndices = searchIndices.Concat(MyCommon.CountUp(0, startIndex - 1));
- }
+ searchIndices = MyCommon.CircularCountUp(this.AllCount, startIndex);
else
- {
- // startIndex ... 先頭
- if (startIndex != 0)
- searchIndices = MyCommon.CountDown(startIndex, 0);
-
- // 末尾 ... (startIndex + 1)
- if (startIndex != this.AllCount - 1)
- searchIndices = searchIndices.Concat(MyCommon.CountDown(this.AllCount - 1, startIndex + 1));
- }
+ searchIndices = MyCommon.CircularCountDown(this.AllCount, startIndex);
foreach (var index in searchIndices)
{
yield return i;
}
+ public static IEnumerable<int> CircularCountUp(int length, int startIndex)
+ {
+ if (length < 1)
+ throw new ArgumentOutOfRangeException(nameof(length));
+ if (startIndex < 0 || startIndex >= length)
+ throw new ArgumentOutOfRangeException(nameof(startIndex));
+
+ // startindex ... 末尾
+ var indices = MyCommon.CountUp(startIndex, length - 1);
+
+ // 先頭 ... (startIndex - 1)
+ if (startIndex != 0)
+ indices = indices.Concat(MyCommon.CountUp(0, startIndex - 1));
+
+ return indices;
+ }
+
+ public static IEnumerable<int> CircularCountDown(int length, int startIndex)
+ {
+ if (length < 1)
+ throw new ArgumentOutOfRangeException(nameof(length));
+ if (startIndex < 0 || startIndex >= length)
+ throw new ArgumentOutOfRangeException(nameof(startIndex));
+
+ // startIndex ... 先頭
+ var indices = MyCommon.CountDown(startIndex, 0);
+
+ // 末尾 ... (startIndex + 1)
+ if (startIndex != length - 1)
+ indices = indices.Concat(MyCommon.CountDown(length - 1, startIndex + 1));
+
+ return indices;
+ }
+
/// <summary>
/// 2バイト文字も考慮したUrlエンコード
/// </summary>