[vector] tests with data providers

Paul Sandoz paul.sandoz at oracle.com
Wed Mar 14 22:17:32 UTC 2018



> On Mar 14, 2018, at 2:38 PM, Halimi, Jean-Philippe <jean-philippe.halimi at intel.com> wrote:
> 
> Hi Paul,
> 
> Sorry for the delayed answer. I think the patch looks good! I just have one remark:
> 

Thanks.


> - In Binary-Masked-op.template, is there a reason why you removed the 3 different mask types?
> 

You were proving three hard coded tests in one method and this could be refactored and generalized into data providers. Each of those masks is now defined here:

static final List<IntFunction<boolean[]>> BOOLEAN_MASK_GENERATORS = List.of(
        withToString("mask[i % 2]", (int l) -> {
            boolean[] a = new boolean[l];
            for (int i = 0; i < l; i++) {
                a[i] = (i % 2 == 0);
            }
            return a;
        }),
        withToString("mask[true]", (int l) -> {
            boolean[] a = new boolean[l];
            Arrays.fill(a, true);
            return a;
        }),
        withToString("mask[false]", boolean[]::new)
);

Then we create the cross product of those 3 masks with pairs of 2 input arrays to produce the arguments input to the binary operations:

@DataProvider
public Object[][] intBinaryOpMaskProvider() {
    return BOOLEAN_MASK_GENERATORS.stream().
            flatMap(fm -> INT_GENERATOR_PAIRS.stream().map(lfa -> {
                return Stream.concat(lfa.stream(), Stream.of(fm)).toArray();
            })).
            toArray(Object[][]::new);
}

In the test output you should see stuff like:

test Short64VectorTests.subShort64VectorTests(short[i * 5], short[i + 1], mask[i % 2]): success
test Short64VectorTests.subShort64VectorTests(short[i * 5], short[i + 1], mask[true]): success
test Short64VectorTests.subShort64VectorTests(short[i * 5], short[i + 1], mask[false]): success

Paul.


More information about the panama-dev mailing list