Skip to content

Commit

Permalink
Fix bug in ArrayIterate.chunk().
Browse files Browse the repository at this point in the history
  • Loading branch information
motlin committed Feb 26, 2016
1 parent 1ada740 commit 11ad219
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015 Goldman Sachs.
* Copyright (c) 2016 Goldman Sachs.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v. 1.0 which accompany this distribution.
Expand Down Expand Up @@ -1487,7 +1487,7 @@ public static <T> RichIterable<RichIterable<T>> chunk(T[] array, int size)
MutableList<T> batch = Lists.mutable.empty();
for (int i = 0; i < size && index < array.length; i++)
{
batch.add(array[i]);
batch.add(array[index]);
index++;
}
result.add(batch);
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015 Goldman Sachs.
* Copyright (c) 2016 Goldman Sachs.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v. 1.0 which accompany this distribution.
Expand Down Expand Up @@ -1215,8 +1215,13 @@ public void chunk()
{
String[] array = {"1", "2", "3", "4", "5", "6", "7"};
RichIterable<RichIterable<String>> groups = ArrayIterate.chunk(array, 2);
RichIterable<Integer> sizes = groups.collect(RichIterable::size);
Assert.assertEquals(FastList.newListWith(2, 2, 2, 1), sizes);
Assert.assertEquals(
Lists.immutable.with(
Lists.immutable.with("1", "2"),
Lists.immutable.with("3", "4"),
Lists.immutable.with("5", "6"),
Lists.immutable.with("7")),
groups);
}

@Test(expected = IllegalArgumentException.class)
Expand Down

0 comments on commit 11ad219

Please sign in to comment.