Regex Point Lambdafication Patch

Paul Sandoz paul.sandoz at oracle.com
Thu Mar 14 03:12:49 PDT 2013


Hi Ben,

I just pushed an enhancement to test code in the lambda repo to support test data that is a supplier of Stream<T>.

Below is some example code you can copy and adjust for your regex tests.

Hth,
Paul.

import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Functions;
import java.util.function.Supplier;
import java.util.stream.OpTestCase;
import java.util.stream.Stream;
import java.util.stream.StreamTestData;
import java.util.stream.Streams;

import static java.util.stream.Collectors.toList;

@Test
public class ExampleStreamTest extends OpTestCase {

    @DataProvider(name = "Stream<String>")
    public static Object[][] makeStreamTestData() {
        List<Object[]> data = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            String description = String.format("range(0, %d)", i);
            List<String> expected = Streams.intRange(0, i).map(Integer::toString).collect(toList());
            Supplier<Stream<String>> s = () -> expected.stream();

            data.add(new Object[]{description, expected, s});
        }

        return data.toArray(new Object[0][]);
    }


    @Test(dataProvider = "Stream<String>")
    public void testStrings(String description, List<String> expected, Supplier<Stream<String>> s) {
        withData(new StreamTestData.StreamSupplierData<>(description, s)).
                stream(Functions.identity()).expectedResult(expected).exercise();
    }
}


On Mar 13, 2013, at 11:51 AM, Paul Sandoz <Paul.Sandoz at oracle.com> wrote:

> Hi Ben,
> 
> On Mar 12, 2013, at 10:33 PM, Ben Evans <benjamin.john.evans at gmail.com> wrote:
> 
>> Thanks Brian.
>> 
>> Does this webrev address the current comments?
>> 
>> http://www.java7developer.com/webrev-kittylyst.002/
>> 
> 
> Can you include Spliterator.NONNULL in the characteristics since I presume input.subSequence will never return a non-null value?
> 
> A useful pattern when writing iterators is to do:
> 
> T next() {
>    if (!hasNext()) throw NoSuchElementException();
>    ...
> }
> 
> so hasNext() when returning true sets up the correct state for next() to obtain the next element e.g.:
> 
> CharSequence next() {
>    if (!hasNext()) throw NoSuchElementException();
> 
>    return input.subsequence(start, end);  
> }
> 
> Once that works once can decide if it is worth optimizing the implementation.
> 
> --
> 
> Testing wise my preference is to add a test ng test extending OpTestCase, add a data provider with the pattern and executed result then use the OpTestCase.exerciseOps or the builder. 
> 
> That will ensure the stream is tested under many different scenarios with reporting for each item of data.
> 
> I can help you with that if you like.
> 
> Paul.
> 



More information about the lambda-dev mailing list