Commits

Inside Zhou committed 6fd0066

Split序列的返回值类型更改为泛型接口,改进测试。

Comments (0)

Files changed (3)

Inside.Util.Test/ListExtensionTest.cs

 		[TestMethod()]
 		public void SplitTest() {
 			var src = new string[] { "a", "b", "c", "1", "2", "3", "c", "d", "e", "4", "5", "6" }.ToList();
-			List<IList<string>> r1 = src.Split(3);
+			var r1 = src.Split(3);
 			Assert.AreEqual("c", r1[0][2]);
 			Assert.AreEqual("3", r1[1][2]);
 			Assert.AreEqual("e", r1[2][2]);
 			Assert.AreEqual("6", r1[3][2]);
 			Assert.AreEqual(4, r1.Count);
 
-			List<IList<string>> r2 = src.Split(4);
+			var r2 = src.Split(4);
 			Assert.AreEqual("c", r2[0][2]);
 			Assert.AreEqual("1", r2[0][3]);
 			Assert.AreEqual("d", r2[1][3]);
 			Assert.AreEqual("e", r2[2][0]);
 			Assert.AreEqual(3, r2.Count);
 
-			List<IList<string>> r3 = src.Split(7);
+			var r3 = src.Split(7);
 			Assert.AreEqual(2, r3.Count);
+
+			var r4 = src.Split(12);
+			Assert.AreEqual(1, r4.Count);
+			Assert.AreEqual(src.Count, r4[0].Count);
+
+			var r5 = src.Split(20);
+			Assert.AreEqual(1, r5.Count);
+			Assert.AreEqual(src.Count, r5[0].Count);
+
+			var r6 = new List<string>().Split(6);
+			Assert.AreEqual(1, r6.Count);
+			Assert.AreEqual(0, r6[0].Count);
 		}
 	}
 }

Inside.Util/ListExtension.cs

 		/// 从列表中随机选择元素。
 		/// </summary>
 		/// <param name="exclusive">选择的元素是否不可重复</param>
-		public static T[] RandomSelect<T>(this IList src, int count = 6, bool exclusive = false) {
-			if(null == src) {
-				throw new ArgumentNullException("src");
-			}
-
+		public static T[] RandomSelect<T>(this IList<T> src, int count = 6, bool exclusive = false) {
 			if(src.Count <= count) {
 				throw new ArgumentException("集合的长度必须大于选择的个数。", "count");
 			}
 		/// <summary>
 		/// 将序列分割成具有指定长度的多个子序列。
 		/// </summary>
-		public static List<IList<T>> Split<T>(this IList<T> src, int length) {
+		public static IList<IList<T>> Split<T>(this IList<T> src, int length) {
 			var result = new List<IList<T>>();
 
-				var list = new List<T>();
+			var list = new List<T>();
 			result.Add(list);
-				var sign = length;
-				for(var index = 0;index < src.Count;++index) {
-					list.Add(src[index]);
+			var sign = length;
+			for(var index = 0;index < src.Count;++index) {
+				list.Add(src[index]);
 				if(index + 1 == sign && sign < src.Count) {
 					sign += length;
 					list = new List<T>();
-						result.Add(list);
+					result.Add(list);
 				}
 			}
 

Inside.Util/Properties/AssemblyInfo.cs

  * 第四位数字表示,bugfix,细节优化这一级别。
  * 版本号互不相关,不再重置为0。
  */
-[assembly: AssemblyVersion("1.5.14.13")]
+[assembly: AssemblyVersion("1.5.14.14")]