開発に使用するリポジトリ
Revision | 7db4f3aa7913c1b353dc9fc6fbc63c4a98155903 (tree) |
---|---|
Time | 2017-08-13 03:29:55 |
Author | Kimura Youichi <kim.upsilon@bucy...> |
Commiter | Kimura Youichi |
検索対象のインデックス番号の生成を MyCommon.CircularCount{Up,Down}() メソッドに分離
@@ -322,5 +322,37 @@ namespace OpenTween | ||
322 | 322 | |
323 | 323 | Assert.Empty(actual); |
324 | 324 | } |
325 | + | |
326 | + [Fact] | |
327 | + public void CircularCountUp_Test() | |
328 | + { | |
329 | + var actual = MyCommon.CircularCountUp(length: 6, startIndex: 3); | |
330 | + | |
331 | + Assert.Equal(new[] { 3, 4, 5, 0, 1, 2 }, actual); | |
332 | + } | |
333 | + | |
334 | + [Fact] | |
335 | + public void CircularCountUp_StartFromZeroTest() | |
336 | + { | |
337 | + var actual = MyCommon.CircularCountUp(length: 6, startIndex: 0); | |
338 | + | |
339 | + Assert.Equal(new[] { 0, 1, 2, 3, 4, 5 }, actual); | |
340 | + } | |
341 | + | |
342 | + [Fact] | |
343 | + public void CircularCountDown_Test() | |
344 | + { | |
345 | + var actual = MyCommon.CircularCountDown(length: 6, startIndex: 3); | |
346 | + | |
347 | + Assert.Equal(new[] { 3, 2, 1, 0, 5, 4 }, actual); | |
348 | + } | |
349 | + | |
350 | + [Fact] | |
351 | + public void CircularCountDown_StartFromLastIndexTest() | |
352 | + { | |
353 | + var actual = MyCommon.CircularCountDown(length: 6, startIndex: 5); | |
354 | + | |
355 | + Assert.Equal(new[] { 5, 4, 3, 2, 1, 0 }, actual); | |
356 | + } | |
325 | 357 | } |
326 | 358 | } |
@@ -393,28 +393,12 @@ namespace OpenTween.Models | ||
393 | 393 | if (this.AllCount == 0) |
394 | 394 | yield break; |
395 | 395 | |
396 | - var searchIndices = Enumerable.Empty<int>(); | |
396 | + IEnumerable<int> searchIndices; | |
397 | 397 | |
398 | 398 | if (!reverse) |
399 | - { | |
400 | - // startindex ...末尾 | |
401 | - if (startIndex != this.AllCount - 1) | |
402 | - searchIndices = MyCommon.CountUp(startIndex, this.AllCount - 1); | |
403 | - | |
404 | - // 先頭 ... (startIndex - 1) | |
405 | - if (startIndex != 0) | |
406 | - searchIndices = searchIndices.Concat(MyCommon.CountUp(0, startIndex - 1)); | |
407 | - } | |
399 | + searchIndices = MyCommon.CircularCountUp(this.AllCount, startIndex); | |
408 | 400 | else |
409 | - { | |
410 | - // startIndex ... 先頭 | |
411 | - if (startIndex != 0) | |
412 | - searchIndices = MyCommon.CountDown(startIndex, 0); | |
413 | - | |
414 | - // 末尾 ... (startIndex + 1) | |
415 | - if (startIndex != this.AllCount - 1) | |
416 | - searchIndices = searchIndices.Concat(MyCommon.CountDown(this.AllCount - 1, startIndex + 1)); | |
417 | - } | |
401 | + searchIndices = MyCommon.CircularCountDown(this.AllCount, startIndex); | |
418 | 402 | |
419 | 403 | foreach (var index in searchIndices) |
420 | 404 | { |
@@ -1071,6 +1071,40 @@ namespace OpenTween | ||
1071 | 1071 | yield return i; |
1072 | 1072 | } |
1073 | 1073 | |
1074 | + public static IEnumerable<int> CircularCountUp(int length, int startIndex) | |
1075 | + { | |
1076 | + if (length < 1) | |
1077 | + throw new ArgumentOutOfRangeException(nameof(length)); | |
1078 | + if (startIndex < 0 || startIndex >= length) | |
1079 | + throw new ArgumentOutOfRangeException(nameof(startIndex)); | |
1080 | + | |
1081 | + // startindex ... 末尾 | |
1082 | + var indices = MyCommon.CountUp(startIndex, length - 1); | |
1083 | + | |
1084 | + // 先頭 ... (startIndex - 1) | |
1085 | + if (startIndex != 0) | |
1086 | + indices = indices.Concat(MyCommon.CountUp(0, startIndex - 1)); | |
1087 | + | |
1088 | + return indices; | |
1089 | + } | |
1090 | + | |
1091 | + public static IEnumerable<int> CircularCountDown(int length, int startIndex) | |
1092 | + { | |
1093 | + if (length < 1) | |
1094 | + throw new ArgumentOutOfRangeException(nameof(length)); | |
1095 | + if (startIndex < 0 || startIndex >= length) | |
1096 | + throw new ArgumentOutOfRangeException(nameof(startIndex)); | |
1097 | + | |
1098 | + // startIndex ... 先頭 | |
1099 | + var indices = MyCommon.CountDown(startIndex, 0); | |
1100 | + | |
1101 | + // 末尾 ... (startIndex + 1) | |
1102 | + if (startIndex != length - 1) | |
1103 | + indices = indices.Concat(MyCommon.CountDown(length - 1, startIndex + 1)); | |
1104 | + | |
1105 | + return indices; | |
1106 | + } | |
1107 | + | |
1074 | 1108 | /// <summary> |
1075 | 1109 | /// 2バイト文字も考慮したUrlエンコード |
1076 | 1110 | /// </summary> |