Permalink
Browse files

fixed failing unit tests from scarney's patch

  • Loading branch information...
troygoode committed Feb 21, 2012
1 parent ae798ac commit f08ed7e64fe98f0165f3be815f6dafca8b1de1cc
Showing with 29 additions and 12 deletions.
  1. +22 −7 src/PagedList.Tests/SplitAndPartitionFacts.cs
  2. +7 −5 src/PagedList/PagedListExtensions.cs
@@ -12,16 +12,16 @@ public void Partition_Works()
var list = Enumerable.Range(1, 9999);
//act
- var splitList = list.Partition(1000);
+ var partitionList = list.Partition(1000);
//assert
- Assert.Equal(10, splitList.Count());
- Assert.Equal(1000, splitList.First().Count());
- Assert.Equal(999, splitList.Last().Count());
+ Assert.Equal(10, partitionList.Count());
+ Assert.Equal(1000, partitionList.First().Count());
+ Assert.Equal(999, partitionList.Last().Count());
}
[Fact]
- public void Paritiion_Returns_Enumerable_With_One_Item_When_Count_Less_Than_Page_Size()
+ public void Partition_Returns_Enumerable_With_One_Item_When_Count_Less_Than_Page_Size()
{
//arrange
var list = Enumerable.Range(1,10);
@@ -30,8 +30,8 @@ public void Paritiion_Returns_Enumerable_With_One_Item_When_Count_Less_Than_Page
var partitionList = list.Partition(1000);
//assert
- Assert.Equal(1, splitList.Count());
- Assert.Equal(10, splitList.First().Count());
+ Assert.Equal(1, partitionList.Count());
+ Assert.Equal(10, partitionList.First().Count());
}
[Fact]
@@ -48,5 +48,20 @@ public void Split_Works()
Assert.Equal(1000, splitList.First().Count());
Assert.Equal(999, splitList.Last().Count());
}
+
+ [Fact]
+ public void Split_Returns_Pages_Of_One_When_More_Pages_Are_Requested_Than_There_Are_Items_To_Page()
+ {
+ //arrange
+ var list = Enumerable.Range(1, 9);
+
+ //act
+ var splitList = list.Split(10);
+
+ //assert
+ Assert.Equal(9, splitList.Count());
+ Assert.Equal(1, splitList.First().Count());
+ Assert.Equal(1, splitList.Last().Count());
+ }
}
}
@@ -62,11 +62,13 @@ public static IEnumerable<IEnumerable<T>> Split<T>(this IEnumerable<T> superset,
public static IEnumerable<IEnumerable<T>> Partition<T>(this IEnumerable<T> superset, int pageSize)
{
if (superset.Count() < pageSize)
- return new List<IEnumerable<T>> {list};
-
- var numberOfPages = Math.Ceiling(superset.Count() / (double) pageSize);
- for (var i = 0; i < numberOfPages; i++)
- yield return superset.Skip(pageSize * i).Take(pageSize);
+ yield return superset;
+ else
+ {
+ var numberOfPages = Math.Ceiling(superset.Count() / (double)pageSize);
+ for (var i = 0; i < numberOfPages; i++)
+ yield return superset.Skip(pageSize * i).Take(pageSize);
+ }
}
}
}

0 comments on commit f08ed7e

Please sign in to comment.