New StackOverflow Question: Using take(n) more than once on Random sequence

8 views
Skip to first unread message

stacko...@mg.bodar.com

unread,
May 22, 2017, 8:17:34 AM5/22/17
to total...@googlegroups.com

Using take(n) more than once on Random sequence

Asked by user3507131 on 2016-02-24T21:12:54Z

Reply on StackOverflow

I would like to take groups of strings from a Randomized sequence. I found that Randoms.takeFromValues provides a sequence that is most suitable for this. But it does not quiet work as expected. I am sure there is something I am not doing right. Here is a test code, It fails at second assertion as the size of list2 is 2 instead of 3.

@Test
public void totallylazy_random_sequence_test() {
    List<String> strings = list("string-1","string-2","string-3","string-4","string-5","string-6");
    Sequence<String> selector = Randoms.takeFromValues(strings);
    List<String> list1 = selector.take(3).toList();
    List<String> list2 = selector.take(3).toList();
    assertThat(list1.size(), is(3));
    assertThat(list2.size(), is(3));
}
Reply on StackOverflow
Reply all
Reply to author
Forward
0 new messages