下面列出了怎么用org.junit.jupiter.params.ParameterizedTest的API类实例代码及写法,或者点击链接到github查看源代码。
@ParameterizedTest
@MethodSource( "data1" )
public void T_forwardMatch_4( final IBlockIndex index ) throws IOException{
int[] mustReadIndex = { 0 , 3 };
IFilter filter = new ForwardMatchStringFilter( "x" );
List<Integer> resultIndexList = index.getBlockSpreadIndex( filter );
if( resultIndexList == null ){
assertTrue( true );
return;
}
Set<Integer> dic = new HashSet<Integer>();
for( Integer i : resultIndexList ){
dic.add( i );
}
for( int i = 0 ; i < mustReadIndex.length ; i++ ){
assertTrue( dic.contains( mustReadIndex[i] ) );
}
}
@ParameterizedTest
@MethodSource( "data1" )
public void T_notNull_1( final String targetClassName ) throws IOException{
IColumn column = createNotNullColumn( targetClassName );
assertEquals( ( (PrimitiveObject)( column.get(0).getRow() ) ).getShort() , Short.MAX_VALUE );
assertEquals( ( (PrimitiveObject)( column.get(1).getRow() ) ).getShort() , Short.MIN_VALUE );
assertEquals( ( (PrimitiveObject)( column.get(2).getRow() ) ).getShort() , (short)-200 );
assertEquals( ( (PrimitiveObject)( column.get(3).getRow() ) ).getShort() , (short)-300 );
assertEquals( ( (PrimitiveObject)( column.get(4).getRow() ) ).getShort() , (short)-400 );
assertEquals( ( (PrimitiveObject)( column.get(5).getRow() ) ).getShort() , (short)-500 );
assertEquals( ( (PrimitiveObject)( column.get(6).getRow() ) ).getShort() , (short)-600 );
assertEquals( ( (PrimitiveObject)( column.get(7).getRow() ) ).getShort() , (short)700 );
assertEquals( ( (PrimitiveObject)( column.get(8).getRow() ) ).getShort() , (short)800 );
assertEquals( ( (PrimitiveObject)( column.get(9).getRow() ) ).getShort() , (short)900 );
assertEquals( ( (PrimitiveObject)( column.get(10).getRow() ) ).getShort() , (short)0 );
}
@ParameterizedTest
@EnumSource(VCS.class)
void testTagsOnNonEmptyRepository(VCS vcs) throws IOException {
try (var dir = new TemporaryDirectory()) {
var r = Repository.init(dir.path(), vcs);
var readme = dir.path().resolve("README");
Files.write(readme, List.of("Hello, readme!"));
r.add(readme);
r.commit("Add README", "duke", "[email protected]");
var expected = vcs == VCS.GIT ? List.of() : List.of(new Tag("tip"));
assertEquals(expected, r.tags());
}
}
@ParameterizedTest
@MethodSource( "data1" )
public void T_le_3( final IBlockIndex index , final IFilter[] filter ) throws IOException{
int[] mustReadIndex = { 0 , 1 };
List<Integer> resultIndexList = index.getBlockSpreadIndex( filter[8] );
if( resultIndexList == null ){
assertTrue( true );
return;
}
Set<Integer> dic = new HashSet<Integer>();
for( Integer i : resultIndexList ){
dic.add( i );
}
for( int i = 0 ; i < mustReadIndex.length ; i++ ){
assertTrue( dic.contains( mustReadIndex[i] ) );
}
}
@ParameterizedTest
@MethodSource( "data1" )
public void T_notNull_1( final String targetClassName ) throws IOException {
IColumn column = new PrimitiveColumn( ColumnType.DOUBLE , "column" );
column.add( ColumnType.DOUBLE , new DoubleObj( (double)1 ) , 0 );
column.add( ColumnType.DOUBLE , new DoubleObj( (double)2 ) , 1 );
column.add( ColumnType.DOUBLE , new DoubleObj( (double)3 ) , 2 );
column.add( ColumnType.DOUBLE , new DoubleObj( (double)4 ) , 3 );
column.add( ColumnType.DOUBLE , new DoubleObj( (double)5 ) , 4 );
column.add( ColumnType.DOUBLE , new DoubleObj( (double)6 ) , 5 );
column.add( ColumnType.DOUBLE , new DoubleObj( (double)7 ) , 6 );
column.add( ColumnType.DOUBLE , new DoubleObj( (double)8 ) , 7 );
column.add( ColumnType.DOUBLE , new DoubleObj( (double)9 ) , 8 );
column.add( ColumnType.DOUBLE , new DoubleObj( (double)10 ) , 9 );
ColumnBinary columnBinary = create( column , targetClassName );
assertEquals( columnBinary.logicalDataSize , Double.BYTES * 10 );
}
@ParameterizedTest
@EnumSource(VCS.class)
void testNonCheckedOutRepositoryIsHealthy(VCS vcs) throws IOException {
try (var dir1 = new TemporaryDirectory();
var dir2 = new TemporaryDirectory()) {
var r1 = Repository.init(dir1.path(), vcs);
var readme = dir1.path().resolve("README");
Files.write(readme, List.of("Hello, readme!"));
r1.add(readme);
var hash = r1.commit("Add README", "duke", "[email protected]");
r1.tag(hash, "tag", "tagging", "duke", "[email protected]");
var r2 = Repository.init(dir2.path(), vcs);
r2.fetch(r1.root().toUri(), r1.defaultBranch().name());
assertTrue(r2.isHealthy());
}
}
@ParameterizedTest
@MethodSource( "data1" )
public void T_notNull_1( final String targetClassName ) throws IOException {
IColumn column = new PrimitiveColumn( ColumnType.LONG , "column" );
column.add( ColumnType.LONG , new LongObj( (long)1 ) , 0 );
column.add( ColumnType.LONG , new LongObj( (long)2 ) , 1 );
column.add( ColumnType.LONG , new LongObj( (long)3 ) , 2 );
column.add( ColumnType.LONG , new LongObj( (long)4 ) , 3 );
column.add( ColumnType.LONG , new LongObj( (long)5 ) , 4 );
column.add( ColumnType.LONG , new LongObj( (long)6 ) , 5 );
column.add( ColumnType.LONG , new LongObj( (long)7 ) , 6 );
column.add( ColumnType.LONG , new LongObj( (long)8 ) , 7 );
column.add( ColumnType.LONG , new LongObj( (long)9 ) , 8 );
column.add( ColumnType.LONG , new LongObj( (long)10 ) , 9 );
ColumnBinary columnBinary = create( column , targetClassName );
assertEquals( columnBinary.logicalDataSize , Long.BYTES * 10 );
}
@ParameterizedTest
@EnumSource(VCS.class)
void checksForCommit(VCS vcs) throws Exception {
try (var dir = new TemporaryDirectory()) {
var repoPath = dir.path().resolve("repo");
var repo = CheckableRepository.create(repoPath, vcs);
var readme = repoPath.resolve("README");
Files.write(readme, List.of("Hello, readme!"));
repo.add(readme);
var first = repo.commit("Add README", "duke", "[email protected]");
var censusPath = dir.path().resolve("census");
Files.createDirectories(censusPath);
CensusCreator.populateCensusDirectory(censusPath);
var census = Census.parse(censusPath);
var checks = JCheck.checksFor(repo, census, first);
var checkNames = checks.stream()
.map(Check::name)
.collect(Collectors.toSet());
assertEquals(Set.of("whitespace", "reviewers"), checkNames);
}
}
@ParameterizedTest()
@EnumSource(WebhookAction.class)
public void testRegistrationFailure(WebhookAction action) throws Exception {
ApplicationRuntime runtime = new ApplicationRuntime();
runtime.setProperties(
"camel.component.webhook.configuration.webhook-auto-register", "false",
"camel.k.customizer.webhook.enabled", "true",
"camel.k.customizer.webhook.action", action.name());
runtime.getCamelContext().addComponent(
"dummy",
new DummyWebhookComponent(
() -> {
throw new RuntimeException("dummy error");
},
() -> {
throw new RuntimeException("dummy error");
})
);
runtime.addListener(new ContextConfigurer());
runtime.addListener(RoutesConfigurer.forRoutes("classpath:webhook.js"));
Assertions.assertThrows(FailedToCreateRouteException.class, runtime::run);
}
@DisplayName("Bessel - High-Pass")
@ParameterizedTest(name = "{displayName}: filter-order: {0}, algorithm: {1}")
@CsvSource({ "2, 0", "3, 0", "4, 0", "2, 1", "3, 1", "4, 1", "2, 2", "3, 2", "4, 2" })
public void testBesselHighPass(final int filterOrder, final int algorithmVariant) {
final Bessel iirHighPass = new Bessel();
switch (algorithmVariant) {
case 1:
iirHighPass.highPass(filterOrder, 1.0, F_CUT_HIGH, DirectFormAbstract.DIRECT_FORM_I);
break;
case 2:
iirHighPass.highPass(filterOrder, 1.0, F_CUT_HIGH, DirectFormAbstract.DIRECT_FORM_II);
break;
case 0:
default:
iirHighPass.highPass(filterOrder, 1.0, F_CUT_HIGH);
break;
}
final DataSet magHighPass = filterAndGetMagnitudeSpectrum(iirHighPass, demoDataSet);
assertThat("high-pass cut-off", magHighPass.getValue(DIM_X, F_CUT_HIGH), lessThan(EPSILON_DB));
assertThat("high-pass rejection", magHighPass.getValue(DIM_X, 0.1 * F_CUT_HIGH), lessThan(3.0 + EPSILON_DB - 10 * filterOrder));
assertThat("high-pass pass-band ripple", getRange(magHighPass, (int) (N_SAMPLES_FFT * 0.95), N_SAMPLES_FFT), lessThan(2 * EPSILON_DB));
}
@ParameterizedTest
@MethodSource( "data1" )
public void T_lt_2( final IBlockIndex index , final IFilter[] filter ) throws IOException{
int[] mustReadIndex = { 0 };
List<Integer> resultIndexList = index.getBlockSpreadIndex( filter[4] );
if( resultIndexList == null ){
assertTrue( true );
return;
}
Set<Integer> dic = new HashSet<Integer>();
for( Integer i : resultIndexList ){
dic.add( i );
}
for( int i = 0 ; i < mustReadIndex.length ; i++ ){
assertTrue( dic.contains( mustReadIndex[i] ) );
}
}
@ParameterizedTest
@MethodSource( "data1" )
public void T_perfectMatch_3( final IBlockIndex index ) throws IOException{
int[] mustReadIndex = { 0 , 3 };
IFilter filter = new PerfectMatchStringFilter( "d" );
List<Integer> resultIndexList = index.getBlockSpreadIndex( filter );
if( resultIndexList == null ){
assertTrue( true );
return;
}
Set<Integer> dic = new HashSet<Integer>();
for( Integer i : resultIndexList ){
dic.add( i );
}
for( int i = 0 ; i < mustReadIndex.length ; i++ ){
assertTrue( dic.contains( mustReadIndex[i] ) );
}
}
@ParameterizedTest
@ValueSource(
strings = {"certification", "assets/" + ASSET_TYPE, "accounts", "discovery", "rules"})
void testGetNotAuthenticated(String endpoint) {
var response = target(endpoint).request().get();
LOGGER.debug("Endpoint {} returned response code {}", endpoint, response.getStatus());
assertEquals(401, response.getStatus());
}
@ParameterizedTest
@ValueSource(strings = { "ahc",
"http", "netty-http" })
public void httpsProducer(String component) {
RestAssured
.given()
.when()
.get("/test/client/{component}/get-https", component)
.then()
.body(containsString("Czech Republic"));
}
@ParameterizedTest
@MethodSource("data")
void test(ScreenshotShootingStrategy strategy, Class<? extends ShootingStrategy> clazz,
boolean viewportScreenshots, boolean isLandscape, String deviceName)
{
assertThat(strategy.getDecoratedShootingStrategy(new SimpleShootingStrategy(), viewportScreenshots,
isLandscape, deviceName), instanceOf(clazz));
}
@ParameterizedTest
@MethodSource("shapeIdData")
public void ShapeIdValidationsTest(String shapeId, boolean isInvalid) {
try {
ShapeId id = ShapeId.from(shapeId);
if (isInvalid) {
Assertions.fail("Expected ShapeIdSyntaxException for but nothing was raised! " + id);
}
} catch (ShapeIdSyntaxException ex) {
if (!isInvalid) {
Assertions.fail(String.format("Received unexpected validation error: %s", ex.getMessage()));
}
}
}
@ParameterizedTest
@CsvSource({ "1, true", "1, false", "2, true", "2, false", "3, true", "3, false", "4, true", "4, false", "5, true",
"5, false", "6, true", "6, false", "1023, true", "1023, false", "1024, true", "1024, false", "1025, true",
"1025, false", "66000, true", "66000, false" })
public void
identityFullRealFFTTests(final int nSamples, final boolean forward) {
DoubleFFT_1D fft = new DoubleFFT_1D(nSamples);
double[] testSignal1a = generateDelta(2 * nSamples);
double[] testSignal1b = new double[2 * nSamples];
double[] testSignal2a = generateRamp(2 * nSamples, nSamples);
double[] testSignal2b = new double[2 * nSamples];
for (int i = 0; i < nSamples; i++) {
testSignal1b[2 * i] = testSignal1a[i];
testSignal2b[2 * i] = testSignal2a[i];
}
// basic identity tests
if (forward) {
fft.realForwardFull(testSignal1a);
fft.complexForward(testSignal1b);
} else {
fft.realInverseFull(testSignal1a, true);
fft.complexInverse(testSignal1b, true);
}
assertArrayEquals(testSignal1a, testSignal1b, nSamples * FFT_NUMERIC_LIMITS,
"full real vs complex forward delta");
if (forward) {
fft.realForwardFull(testSignal2a);
fft.complexForward(testSignal2b);
} else {
fft.realInverseFull(testSignal2a, true);
fft.complexInverse(testSignal2b, true);
}
assertArrayEquals(testSignal2a, testSignal2b, (nSamples < 2000 ? 1.0f : 10f) * nSamples * FFT_NUMERIC_LIMITS,
"full real vs complex forward ramp");
}
@ParameterizedTest
@CsvSource({
"''",
"' '"
})
void shouldSetNullValueForBlankText(String value)
{
CookieStoreLevelEditor cookieStoreLevelEditor = new CookieStoreLevelEditor();
cookieStoreLevelEditor.setAsText(value);
assertNull(cookieStoreLevelEditor.getValue());
}
@ParameterizedTest
@EnumSource(VCS.class)
void testRangeExclusive(VCS vcs) throws IOException {
try (var dir = new TemporaryDirectory()) {
var repo = Repository.init(dir.path(), vcs);
var range = repo.rangeExclusive(new Hash("01234"), new Hash("56789"));
if (vcs == VCS.GIT) {
assertEquals("01234..56789", range);
} else if (vcs == VCS.HG) {
assertEquals("01234:56789-01234", range);
} else {
fail("Unexpected vcs: " + vcs);
}
}
}
@ParameterizedTest
@MethodSource( "data1" )
public void T_match_2( final IColumn column ) throws IOException{
int[] mustReadIndex = { 1 , 3 , 5 , 7 , 9 , 21 , 23 , 25 , 27 , 29 };
IFilter filter = new BooleanFilter( false );
boolean[] filterResult = new boolean[30];
filterResult = column.filter( filter , filterResult );
if( filterResult == null ){
assertTrue( true );
return;
}
for( int i = 0 ; i < mustReadIndex.length ; i++ ){
assertTrue( filterResult[mustReadIndex[i]] );
}
}
@ParameterizedTest
@MethodSource( "data1" )
public void T_hasNull_1( final String targetClassName ) throws IOException{
IColumn column = createHasNullColumn( targetClassName );
assertEquals( ( (PrimitiveObject)( column.get(0).getRow() ) ).getInt() , (int)0 );
assertNull( column.get(1).getRow() );
assertNull( column.get(2).getRow() );
assertNull( column.get(3).getRow() );
assertEquals( ( (PrimitiveObject)( column.get(4).getRow() ) ).getInt() , (int)4 );
assertNull( column.get(5).getRow() );
assertNull( column.get(6).getRow() );
assertNull( column.get(7).getRow() );
assertEquals( ( (PrimitiveObject)( column.get(8).getRow() ) ).getInt() , (int)8 );
}
@ParameterizedTest
@EnumSource(VCS.class)
void testExistsOnMissingDirectory(VCS vcs) throws IOException {
var d = Paths.get("/", "this", "path", "does", "not", "exist");
var r = Repository.get(d);
assertTrue(r.isEmpty());
}
/**
* 测试装载语种检测规则
*
* @param path
* @param size
*/
@ParameterizedTest
@CsvSource({ "regulation-82.json,20", "regulation-187.json,30", "regulation-406.json,37" })
public void testLoadPattern(String path, int size) {
try (InputStream stream = DetectionPattern.class.getResourceAsStream(path)) {
Map<String, DetectionPattern> regulations = DetectionPattern.loadPatterns(stream);
Assertions.assertEquals(size, regulations.size());
} catch (Exception exception) {
throw new IllegalArgumentException(exception);
}
}
@ParameterizedTest
@CsvSource({
", body",
"OBJECT, "
})
void testExecuteJavascriptWithArgumentsNoType(JsArgumentType type, String value)
{
JsArgument argument = createJsArgument(type, value);
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class,
() -> codeSteps.executeJavascriptWithArguments("document.querySelector(arguments[0])",
Collections.singletonList(argument)));
assertEquals(JS_ARGUMENT_ERROR_MESSAGE, exception.getMessage());
}
@ParameterizedTest
@MethodSource( "data1" )
public void T_filter_1( final ICellIndex cIndex , final IFilter filter , final boolean[] result ) throws IOException{
boolean[] r = cIndex.filter( filter , new boolean[0] );
if( r == null ){
assertNull( result );
}
else{
assertEquals( result.length , 0 );
}
}
@MethodSource("stringContentTypes")
@ParameterizedTest
void testAddStringPart(Optional<String> contentTypeAsString, ContentType contentType)
throws IOException
{
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
String name = "stringKey";
String value = "stringValue";
RequestPartType.STRING.addPart(builder, name, value, contentTypeAsString);
assertHttpEntity(builder, buildExpectedEntity(name, contentType, "8bit", value));
}
@ParameterizedTest
@CsvSource({
"test, true",
"tt, true",
"ttt, false",
"es, true",
"se, false",
", true"
})
public void test(String value, boolean expected){
assertThat(StringUtils.containsLettersInOrder("test", value)).isEqualTo(expected);
}
@DisplayName("Bessel - Band-Stop")
@ParameterizedTest(name = "{displayName}: filter-order: {0}, algorithm: {1}")
@CsvSource({ "2, 0", "3, 0", "4, 0", "2, 1", "3, 1", "4, 1", "2, 2", "3, 2", "4, 2" })
public void testBesselBandStop(final int filterOrder, final int algorithmVariant) {
final Bessel iirBandStop = new Bessel();
switch (algorithmVariant) {
case 1:
iirBandStop.bandStop(filterOrder, 1.0, F_BAND_CENTRE, F_BAND_WIDTH, DirectFormAbstract.DIRECT_FORM_I);
break;
case 2:
iirBandStop.bandStop(filterOrder, 1.0, F_BAND_CENTRE, F_BAND_WIDTH, DirectFormAbstract.DIRECT_FORM_II);
break;
case 0:
default:
iirBandStop.bandStop(filterOrder, 1.0, F_BAND_CENTRE, F_BAND_WIDTH);
break;
}
final DataSet magBandStop = filterAndGetMagnitudeSpectrum(iirBandStop, demoDataSet);
assertThat("band-stop cut-off (low)", magBandStop.getValue(DIM_X, F_BAND_START), lessThan(EPSILON_DB));
assertThat("band-stop cut-off (high)", magBandStop.getValue(DIM_X, F_BAND_STOP), lessThan(EPSILON_DB));
assertThat("band-pass pass-band (low)", getRange(magBandStop, 0, magBandStop.getIndex(DIM_X, F_BAND_START * 0.1)), lessThan(EPSILON_DB));
assertThat("band-pass pass-band (high)", getRange(magBandStop, (int) (N_SAMPLES_FFT * 0.95), N_SAMPLES_FFT), lessThan(EPSILON_DB));
final double rangeStopBand = getMaximum(magBandStop,
magBandStop.getIndex(DIM_X, (F_BAND_CENTRE - 0.03 * F_BAND_WIDTH)),
magBandStop.getIndex(DIM_X, (F_BAND_CENTRE + 0.03 * F_BAND_WIDTH)));
assertThat("band-pass stop-band ripple", rangeStopBand, lessThan(3.0 + EPSILON_DB - 10 * filterOrder));
}
@ParameterizedTest(name = "toInstantByRegexPositive({0},{1},{2},{3})")
@MethodSource("toInstantByRegexPositiveSource")
public void toInstantByRegexPositive(long expectedSeconds, long expectedNanos, String pattern,
String value) {
var cut = getCut();
var p = Pattern.compile(pattern);
var m = p.matcher(value);
assertTrue(m.find());
var inst = cut.toInstant(m);
assertAll(() -> assertEquals(expectedSeconds, inst.getEpochSecond()),
() -> assertEquals(expectedNanos, inst.getNano())
);
}
@ParameterizedTest
@ValueSource(strings = {"public", "custom"})
void getDuplicatedIndexesWithDifferentCollationShouldReturnNothing(final String schemaName) {
executeTestOnDatabase(schemaName,
dbp -> dbp.withReferences().withCustomCollation().withDuplicatedCustomCollationIndex(),
ctx -> {
final List<DuplicatedIndexes> duplicatedIndexes = databaseHealth.getDuplicatedIndexes(ctx);
assertNotNull(duplicatedIndexes);
assertThat(duplicatedIndexes, empty());
});
}