Skip to content

Commit 4712003

Browse files
authored
Merge pull request #41 from I-RzR-I/fix/Fix_Enumerable_Chunked
Fix enumerable chunked
2 parents 126895a + 7d64eff commit 4712003

5 files changed

Lines changed: 108 additions & 5 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
This library/ repository was created as a way to simplify the development process. Here were written the usually used methods (extension methods) for some data types like `int, string, DateTime, Enum, bool, byte, Guid`, also there was added extensions for `List, Dictionary, DynamicList` and other collections(`ICollection, IEnumerable, IList, HashSet, IQueryable`).
77

8-
In the repository was added an extension for `cryptography`, encrypting and decrypting string by key with RSA.
8+
In the repository was added an extension for `cryptography`, encrypting and decrypting string by key with `RSA`, `AES`, `TEA``
99

1010
In case you need some get some documentation/comments from `Assembly`, here too are some extensions.
1111

docs/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
### **v4.0.1.8519** [[RzR](mailto:108324929+I-RzR-I@users.noreply.github.com)] 27-10-2025
2+
* [2726a87] (RzR) -> Auto commit uncommited files
3+
* [1282898] (RzR) -> Fix IEnumerable extension method: `Chunked`.
4+
15
### **v4.0.0.5323** [[RzR](mailto:108324929+I-RzR-I@users.noreply.github.com)] 14-10-2025
26
* [c464d6d] (RzR) -> Add `TEA` extensions `TEAEncrypt`, `TEADecrypt`.
37
* [ea248b6] (RzR) -> Implement `TEA` helper.

src/DomainCommonExtensions/ArraysExtensions/EnumerableExtensions.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,7 @@ public static IEnumerable<IEnumerable<T>> Chunked<T>(this IEnumerable<T> source,
710710
{
711711
if (source.IsNullOrEmptyEnumerable())
712712
return new List<IEnumerable<T>>();
713+
713714
if (chunkSize.IsNull() || chunkSize.IsLessOrEqualZero())
714715
return new List<IEnumerable<T>>(1) { source };
715716

@@ -720,7 +721,7 @@ public static IEnumerable<IEnumerable<T>> Chunked<T>(this IEnumerable<T> source,
720721
for (var chunkIndex = 0; chunkIndex < chunksCount; chunkIndex++)
721722
{
722723
var newChunkSize = chunkIndex == chunksCount - 1 ? chunkArray.Length - (chunkSize * chunkIndex) : chunkSize;
723-
var newChunkSourceIndex = chunkIndex.IsZero() ? chunkIndex : (chunkSize * chunkIndex) - 1;
724+
var newChunkSourceIndex = chunkIndex.IsZero() ? chunkIndex : (chunkSize * chunkIndex)/* -1*/;
724725

725726
var chunk = new T[newChunkSize];
726727
Array.Copy(chunkArray, newChunkSourceIndex, chunk, 0, newChunkSize);

src/shared/GeneralAssemblyInfo.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,6 @@
4747
[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.MainAssembly)]
4848
#endif
4949

50-
[assembly: AssemblyVersion("4.0.0.5323")]
51-
[assembly: AssemblyFileVersion("4.0.0.5323")]
52-
[assembly: AssemblyInformationalVersion("4.0.0.5323")]
50+
[assembly: AssemblyVersion("4.0.1.8519")]
51+
[assembly: AssemblyFileVersion("4.0.1.8519")]
52+
[assembly: AssemblyInformationalVersion("4.0.1.8519")]

src/tests/DataTypeTests/DataTests/Array/EnumerableTests.cs

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,19 @@ public void ChunkArray_Chunked_2_Test()
5858
Assert.AreEqual(2, chunks[3].Count());
5959
Assert.AreEqual(2, chunks[4].Count());
6060
Assert.AreEqual(2, chunks[5].Count());
61+
62+
63+
Assert.AreEqual(1, chunks[0].ElementAt(0));
64+
Assert.AreEqual(2, chunks[0].ElementAt(1));
65+
66+
Assert.AreEqual(3, chunks[1].ElementAt(0));
67+
Assert.AreEqual(4, chunks[1].ElementAt(1));
68+
69+
Assert.AreEqual(5, chunks[2].ElementAt(0));
70+
Assert.AreEqual(6, chunks[2].ElementAt(1));
71+
72+
Assert.AreEqual(7, chunks[3].ElementAt(0));
73+
Assert.AreEqual(8, chunks[3].ElementAt(1));
6174
}
6275

6376
[TestMethod]
@@ -70,6 +83,91 @@ public void ChunkArray_Chunked_20_Test()
7083
Assert.IsNotNull(chunks);
7184
Assert.AreEqual(1, chunks.Count());
7285
Assert.AreEqual(12, chunks[0].Count());
86+
87+
Assert.IsTrue(chunks[0].ElementAt(0) == 1);
88+
Assert.IsTrue(chunks[0].ElementAt(5) == 6);
89+
Assert.IsTrue(chunks[0].ElementAt(10) == 11);
90+
Assert.IsTrue(chunks[0].ElementAt(11) == 12);
91+
}
92+
93+
[TestMethod]
94+
public void ChunkArray_Chunked_20_To_10_Test()
95+
{
96+
var arrInput = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
97+
98+
var chunks = arrInput.Chunked(10).ToArray();
99+
100+
Assert.IsNotNull(chunks);
101+
Assert.AreEqual(2, chunks.Count());
102+
Assert.AreEqual(10, chunks[0].Count());
103+
104+
Assert.AreEqual(1, chunks[0].ElementAt(0));
105+
Assert.AreEqual(10, chunks[0].ElementAt(9));
106+
Assert.AreEqual(11, chunks[1].ElementAt(0));
107+
Assert.AreEqual(20, chunks[1].ElementAt(9));
108+
}
109+
110+
[TestMethod]
111+
public void ChunkArray_Chunked_3_To_2_Test()
112+
{
113+
var arrInput = new int[] { 1, 2, 3 };
114+
115+
var chunks = arrInput.Chunked(2).ToArray();
116+
117+
Assert.IsNotNull(chunks);
118+
Assert.AreEqual(2, chunks.Count());
119+
Assert.AreEqual(2, chunks[0].Count());
120+
Assert.AreEqual(1, chunks[1].Count());
121+
122+
Assert.AreEqual(1, chunks[0].ElementAt(0));
123+
Assert.AreEqual(2, chunks[0].ElementAt(1));
124+
Assert.AreEqual(3, chunks[1].ElementAt(0));
125+
}
126+
127+
[TestMethod]
128+
public void ChunkArray_Null_Chunked_Test()
129+
{
130+
int[] arrInput = null;
131+
132+
var chunks = arrInput.Chunked(2).ToArray();
133+
134+
Assert.IsNotNull(chunks);
135+
Assert.AreEqual(0, chunks.Count());
136+
}
137+
138+
[TestMethod]
139+
public void ChunkArray_Empty_Chunked_Test()
140+
{
141+
var arrInput = new int[] { };
142+
143+
var chunks = arrInput.Chunked(2).ToArray();
144+
145+
Assert.IsNotNull(chunks);
146+
Assert.AreEqual(0, chunks.Count());
147+
}
148+
149+
[TestMethod]
150+
public void ChunkArray_Chunked_0_Test()
151+
{
152+
var arrInput = new int[] { 1, 2, 3 };
153+
154+
var chunks = arrInput.Chunked(0).ToArray();
155+
156+
Assert.IsNotNull(chunks);
157+
Assert.AreEqual(1, chunks.Count());
158+
Assert.AreEqual(3, chunks[0].Count());
159+
}
160+
161+
[TestMethod]
162+
public void ChunkArray_Chunked_LessTanZero_Test()
163+
{
164+
var arrInput = new int[] { 1, 2, 3 };
165+
166+
var chunks = arrInput.Chunked(-10).ToArray();
167+
168+
Assert.IsNotNull(chunks);
169+
Assert.AreEqual(1, chunks.Count());
170+
Assert.AreEqual(3, chunks[0].Count());
73171
}
74172

75173
[TestMethod]

0 commit comments

Comments
 (0)