• R/O
  • HTTP
  • SSH
  • HTTPS

open-tween: Commit

開発に使用するリポジトリ


Commit MetaInfo

Revision7db4f3aa7913c1b353dc9fc6fbc63c4a98155903 (tree)
Time2017-08-13 03:29:55
AuthorKimura Youichi <kim.upsilon@bucy...>
CommiterKimura Youichi

Log Message

検索対象のインデックス番号の生成を MyCommon.CircularCount{Up,Down}() メソッドに分離

Change Summary

Incremental Difference

--- a/OpenTween.Tests/MyCommonTest.cs
+++ b/OpenTween.Tests/MyCommonTest.cs
@@ -322,5 +322,37 @@ namespace OpenTween
322322
323323 Assert.Empty(actual);
324324 }
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+ }
325357 }
326358 }
--- a/OpenTween/Models/TabModel.cs
+++ b/OpenTween/Models/TabModel.cs
@@ -393,28 +393,12 @@ namespace OpenTween.Models
393393 if (this.AllCount == 0)
394394 yield break;
395395
396- var searchIndices = Enumerable.Empty<int>();
396+ IEnumerable<int> searchIndices;
397397
398398 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);
408400 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);
418402
419403 foreach (var index in searchIndices)
420404 {
--- a/OpenTween/MyCommon.cs
+++ b/OpenTween/MyCommon.cs
@@ -1071,6 +1071,40 @@ namespace OpenTween
10711071 yield return i;
10721072 }
10731073
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+
10741108 /// <summary>
10751109 /// 2バイト文字も考慮したUrlエンコード
10761110 /// </summary>
Show on old repository browser