org.junit.jupiter.params.provider.CsvSource Java Examples

The following examples show how to use org.junit.jupiter.params.provider.CsvSource. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ValidatorTest.java    From aws-cloudformation-resource-schema with Apache License 2.0 7 votes vote down vote up
@ParameterizedTest
@CsvSource({ "test,minProperties", "test-test1-test2,maxProperties", "test-dep,dependencies" })
public void validateObject_invalidSubObject_messageShouldNotContainValue(final String keysAsString, final String keyword) {
    final String val = "testValue";
    final JSONObject subSchema = new JSONObject();

    final List<String> keys = Arrays.asList(keysAsString.split("-"));
    keys.forEach(k -> subSchema.put(k, val));

    final JSONObject object = new JSONObject().put("ObjectProperty", subSchema);

    final ValidationException e = catchThrowableOfType(
        () -> validator.validateObject(object,
            new JSONObject(new JSONTokener(this.getClass().getResourceAsStream(TEST_VALUE_SCHEMA_PATH)))),
        ValidationException.class);

    assertThat(e.getKeyword()).isEqualTo(keyword);
    assertThat(e.getSchemaPointer()).isEqualTo("#/ObjectProperty");
    assertThat(e).hasMessageNotContaining(val);
    assertThat(e.getCausingExceptions()).isEmpty();
}
 
Example #2
Source File: UtilityTest.java    From hedera-mirror-node with Apache License 2.0 6 votes vote down vote up
@ParameterizedTest(name = "verifyHashChain {5}")
@CsvSource({
        // @formatter:off
        "'', '', 1970-01-01T00:00:00Z,        2000-01-01T10_00_00.000000Z.rcd, true,  passes if both hashes are empty",
        "xx, '', 1970-01-01T00:00:00Z,        2000-01-01T10_00_00.000000Z.rcd, true,  passes if hash mismatch and expected hash is empty", // starting stream in middle
        "'', xx, 1970-01-01T00:00:00Z,        2000-01-01T10_00_00.000000Z.rcd, false, fails if hash mismatch and actual hash is empty", // bad db state
        "xx, yy, 1970-01-01T00:00:00Z,        2000-01-01T10_00_00.000000Z.rcd, false, fails if hash mismatch and hashes are non-empty",
        "xx, yy, 2000-01-01T10:00:00.000001Z, 2000-01-01T10_00_00.000000Z.rcd, true,  passes if hash mismatch but verifyHashAfter is after filename",
        "xx, yy, 2000-01-01T10:00:00.000001Z, 2000-01-01T10_00_00.000000Z.rcd, true,  passes if hash mismatch but verifyHashAfter is same as filename",
        "xx, yy, 2000-01-01T09:59:59.999999Z, 2000-01-01T10_00_00.000000Z.rcd, false, fails if hash mismatch and verifyHashAfter is before filename",
        "xx, xx, 1970-01-01T00:00:00Z,        2000-01-01T10_00_00.000000Z.rcd, true,  passes if hashes are equal"
        // @formatter:on
})
public void testVerifyHashChain(String actualPrevFileHash, String expectedPrevFileHash,
                                @ConvertWith(InstantConverter.class) Instant verifyHashAfter, String fileName,
                                Boolean expectedResult, String testName) {
    assertThat(Utility.verifyHashChain(actualPrevFileHash, expectedPrevFileHash, verifyHashAfter, fileName))
            .isEqualTo(expectedResult);
}
 
Example #3
Source File: BytesSSZReaderTest.java    From incubator-tuweni with Apache License 2.0 6 votes vote down vote up
@ParameterizedTest
// @formatter:off
@CsvSource({
  "00000000, ''",
  "0100000000, '\u0000'",
  "0100000001, '\u0001'",
  "010000007f, '\u007F'",
  "03000000646f67, dog",
  "370000004C6F72656D20697073756D20646F6C6F722073697420616D65742C20636F6E7365637465747572206164697069736963696E6720656C69" +
  ", 'Lorem ipsum dolor sit amet, consectetur adipisicing eli'",
  "380000004C6F72656D20697073756D20646F6C6F722073697420616D65742C20636F6E7365637465747572206164697069736963696E6720656C6974" +
  ", 'Lorem ipsum dolor sit amet, consectetur adipisicing elit'",
  "000400004C6F72656D20697073756D20646F6C6F722073697420616D65742C20636F6E73656374657475722061646970697363696E6720656C69742E20437572616269747572206D6175726973206D61676E612C20737573636970697420736564207665686963756C61206E6F6E2C20696163756C697320666175636962757320746F72746F722E2050726F696E20737573636970697420756C74726963696573206D616C6573756164612E204475697320746F72746F7220656C69742C2064696374756D2071756973207472697374697175652065752C20756C7472696365732061742072697375732E204D6F72626920612065737420696D70657264696574206D6920756C6C616D636F7270657220616C6971756574207375736369706974206E6563206C6F72656D2E2041656E65616E2071756973206C656F206D6F6C6C69732C2076756C70757461746520656C6974207661726975732C20636F6E73657175617420656E696D2E204E756C6C6120756C74726963657320747572706973206A7573746F2C20657420706F73756572652075726E6120636F6E7365637465747572206E65632E2050726F696E206E6F6E20636F6E76616C6C6973206D657475732E20446F6E65632074656D706F7220697073756D20696E206D617572697320636F6E67756520736F6C6C696369747564696E2E20566573746962756C756D20616E746520697073756D207072696D697320696E206661756369627573206F726369206C756374757320657420756C74726963657320706F737565726520637562696C69612043757261653B2053757370656E646973736520636F6E76616C6C69732073656D2076656C206D617373612066617563696275732C2065676574206C6163696E6961206C616375732074656D706F722E204E756C6C61207175697320756C747269636965732070757275732E2050726F696E20617563746F722072686F6E637573206E69626820636F6E64696D656E74756D206D6F6C6C69732E20416C697175616D20636F6E73657175617420656E696D206174206D65747573206C75637475732C206120656C656966656E6420707572757320656765737461732E20437572616269747572206174206E696268206D657475732E204E616D20626962656E64756D2C206E6571756520617420617563746F72207472697374697175652C206C6F72656D206C696265726F20616C697175657420617263752C206E6F6E20696E74657264756D2074656C6C7573206C65637475732073697420616D65742065726F732E20437261732072686F6E6375732C206D65747573206163206F726E617265206375727375732C20646F6C6F72206A7573746F20756C747269636573206D657475732C20617420756C6C616D636F7270657220766F6C7574706174" +
  ", 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur mauris magna, suscipit sed vehicula non, iaculis faucibus tortor. Proin suscipit ultricies malesuada. Duis tortor elit, dictum quis tristique eu, ultrices at risus. Morbi a est imperdiet mi ullamcorper aliquet suscipit nec lorem. Aenean quis leo mollis, vulputate elit varius, consequat enim. Nulla ultrices turpis justo, et posuere urna consectetur nec. Proin non convallis metus. Donec tempor ipsum in mauris congue sollicitudin. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Suspendisse convallis sem vel massa faucibus, eget lacinia lacus tempor. Nulla quis ultricies purus. Proin auctor rhoncus nibh condimentum mollis. Aliquam consequat enim at metus luctus, a eleifend purus egestas. Curabitur at nibh metus. Nam bibendum, neque at auctor tristique, lorem libero aliquet arcu, non interdum tellus lectus sit amet eros. Cras rhoncus, metus ac ornare cursus, dolor justo ultrices metus, at ullamcorper volutpat'"
})
// @formatter:on
void shouldReadStrings(String hex, String value) {
  System.out.println(SSZ.encodeString(value));
  assertTrue(SSZ.<Boolean>decode(fromHexString(hex), reader -> {
    assertEquals(value, reader.readString());
    return true;
  }));
}
 
Example #4
Source File: VividusLabelTests.java    From vividus with Apache License 2.0 6 votes vote down vote up
@ParameterizedTest
@CsvSource({
        "TEST_CASE_ID,   tms",
        "ISSUE_ID,       issue",
        "REQUIREMENT_ID, requirement"
})
void shouldCreateLink(VividusLabel vividusLabel, String type)
{
    String identifier = "VVD-5";
    Optional<Link> optionalLink = vividusLabel.createLink(identifier);
    assertTrue(optionalLink.isPresent());
    Link link = optionalLink.get();
    assertAll(
        () -> assertEquals(identifier, link.getName()),
        () -> assertEquals(type, link.getType()),
        () -> assertEquals(HTTPS + type + "/" + identifier, link.getUrl())
    );
}
 
Example #5
Source File: WebDriverProviderTests.java    From vividus with Apache License 2.0 6 votes vote down vote up
@ParameterizedTest
@CsvSource({
    "false, false, false",
    "true, false, false",
    "true, true, true"
})
void testIsRemoteExecution(boolean initialized, boolean remote, boolean expected)
{
    WebDriverProvider spy = spy(webDriverProvider);
    testContext.put(VividusWebDriver.class, vividusWebDriver);

    when(spy.isWebDriverInitialized()).thenReturn(initialized);
    lenient().when(vividusWebDriver.isRemote()).thenReturn(remote);

    assertEquals(expected, spy.isRemoteExecution());
}
 
Example #6
Source File: TSpectrumTests.java    From chart-fx with Apache License 2.0 6 votes vote down vote up
@ParameterizedTest
@CsvSource({ "10, 1", "1, 2", "0.1, 3", "0.01, 4" })
public void peakFinderTests(double threshold, final int nPeaks) {
    DoubleDataSet testDataSet = generateSineWaveSpectrumData(512);
    final double[] freq = testDataSet.getXValues();
    final double[] rawDataDecibel = testDataSet.getYValues();
    final double[] dataLin = ArrayMath.inverseDecibel(rawDataDecibel);

    double[] destVector = new double[dataLin.length];
    final int nMaxPeaks = 100;
    final double sigma = 1.0;
    List<DoublePoint> peaks = TSpectrum.search(freq, ArrayMath.inverseDecibel(rawDataDecibel), destVector, //
            dataLin.length, nMaxPeaks, sigma, threshold, //
            /* backgroundRemove */ false, //
            /* deconIterations */ 1, //
            /* markov */ false, //
            /* averWindow */ 5);

    assertEquals(nPeaks, peaks.size(), "peak finder with threshold = " + threshold);
}
 
Example #7
Source File: VividusLabelTests.java    From vividus with Apache License 2.0 6 votes vote down vote up
@ParameterizedTest
@CsvSource({
        "TEST_CASE_ID,   testCaseId",
        "ISSUE_ID,       issueId",
        "REQUIREMENT_ID, requirementId",
        "SEVERITY,       severity",
        "EPIC,           epic",
        "FEATURE,        feature"
})
void shouldCreateLabel(VividusLabel vividusLabel, String expectedName)
{
    String value = "value";
    Label label = vividusLabel.createLabel(value);
    assertAll(
        () -> assertEquals(expectedName, label.getName()),
        () -> assertEquals(value, label.getValue())
    );
}
 
Example #8
Source File: BytesRLPReaderTest.java    From incubator-tuweni with Apache License 2.0 6 votes vote down vote up
@ParameterizedTest
// @formatter:off
@CsvSource({
  "80, ''",
  "00, '\u0000'",
  "01, '\u0001'",
  "7f, '\u007F'",
  "83646f67, dog",
  "b74c6f72656d20697073756d20646f6c6f722073697420616d65742c20636f6e7365637465747572206164697069736963696e6720656c69" +
  ", 'Lorem ipsum dolor sit amet, consectetur adipisicing eli'",
  "b8384c6f72656d20697073756d20646f6c6f722073697420616d65742c20636f6e7365637465747572206164697069736963696e6720656c6974" +
  ", 'Lorem ipsum dolor sit amet, consectetur adipisicing elit'",
  "b904004c6f72656d20697073756d20646f6c6f722073697420616d65742c20636f6e73656374657475722061646970697363696e6720656c69742e20437572616269747572206d6175726973206d61676e612c20737573636970697420736564207665686963756c61206e6f6e2c20696163756c697320666175636962757320746f72746f722e2050726f696e20737573636970697420756c74726963696573206d616c6573756164612e204475697320746f72746f7220656c69742c2064696374756d2071756973207472697374697175652065752c20756c7472696365732061742072697375732e204d6f72626920612065737420696d70657264696574206d6920756c6c616d636f7270657220616c6971756574207375736369706974206e6563206c6f72656d2e2041656e65616e2071756973206c656f206d6f6c6c69732c2076756c70757461746520656c6974207661726975732c20636f6e73657175617420656e696d2e204e756c6c6120756c74726963657320747572706973206a7573746f2c20657420706f73756572652075726e6120636f6e7365637465747572206e65632e2050726f696e206e6f6e20636f6e76616c6c6973206d657475732e20446f6e65632074656d706f7220697073756d20696e206d617572697320636f6e67756520736f6c6c696369747564696e2e20566573746962756c756d20616e746520697073756d207072696d697320696e206661756369627573206f726369206c756374757320657420756c74726963657320706f737565726520637562696c69612043757261653b2053757370656e646973736520636f6e76616c6c69732073656d2076656c206d617373612066617563696275732c2065676574206c6163696e6961206c616375732074656d706f722e204e756c6c61207175697320756c747269636965732070757275732e2050726f696e20617563746f722072686f6e637573206e69626820636f6e64696d656e74756d206d6f6c6c69732e20416c697175616d20636f6e73657175617420656e696d206174206d65747573206c75637475732c206120656c656966656e6420707572757320656765737461732e20437572616269747572206174206e696268206d657475732e204e616d20626962656e64756d2c206e6571756520617420617563746f72207472697374697175652c206c6f72656d206c696265726f20616c697175657420617263752c206e6f6e20696e74657264756d2074656c6c7573206c65637475732073697420616d65742065726f732e20437261732072686f6e6375732c206d65747573206163206f726e617265206375727375732c20646f6c6f72206a7573746f20756c747269636573206d657475732c20617420756c6c616d636f7270657220766f6c7574706174" +
  ", 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur mauris magna, suscipit sed vehicula non, iaculis faucibus tortor. Proin suscipit ultricies malesuada. Duis tortor elit, dictum quis tristique eu, ultrices at risus. Morbi a est imperdiet mi ullamcorper aliquet suscipit nec lorem. Aenean quis leo mollis, vulputate elit varius, consequat enim. Nulla ultrices turpis justo, et posuere urna consectetur nec. Proin non convallis metus. Donec tempor ipsum in mauris congue sollicitudin. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Suspendisse convallis sem vel massa faucibus, eget lacinia lacus tempor. Nulla quis ultricies purus. Proin auctor rhoncus nibh condimentum mollis. Aliquam consequat enim at metus luctus, a eleifend purus egestas. Curabitur at nibh metus. Nam bibendum, neque at auctor tristique, lorem libero aliquet arcu, non interdum tellus lectus sit amet eros. Cras rhoncus, metus ac ornare cursus, dolor justo ultrices metus, at ullamcorper volutpat'"
})
// @formatter:on
void shouldReadStrings(String hex, String value) {
  assertTrue(RLP.<Boolean>decode(fromHexString(hex), reader -> {
    assertEquals(value, reader.readString());
    return true;
  }));
}
 
Example #9
Source File: IirFilterTests.java    From chart-fx with Apache License 2.0 6 votes vote down vote up
@DisplayName("ChebyshevI - 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 testChebyshevIHighPass(final int filterOrder, final int algorithmVariant) {
    final ChebyshevI iirHighPass = new ChebyshevI();
    switch (algorithmVariant) {
    case 1:
        iirHighPass.highPass(filterOrder, 1.0, F_CUT_HIGH, ALLOWED_IN_BAND_RIPPLE_DB, DirectFormAbstract.DIRECT_FORM_I);
        break;
    case 2:
        iirHighPass.highPass(filterOrder, 1.0, F_CUT_HIGH, ALLOWED_IN_BAND_RIPPLE_DB, DirectFormAbstract.DIRECT_FORM_II);
        break;
    case 0:
    default:
        iirHighPass.highPass(filterOrder, 1.0, F_CUT_HIGH, ALLOWED_IN_BAND_RIPPLE_DB);
        break;
    }

    final DataSet magHighPass = filterAndGetMagnitudeSpectrum(iirHighPass, demoDataSet);
    assertThat("high-pass cut-off", magHighPass.getValue(DIM_X, F_CUT_HIGH), lessThan(-3.0 + EPSILON_DB));
    assertThat("high-pass rejection", magHighPass.getValue(DIM_X, 0.1 * F_CUT_HIGH), lessThan(-3.0 + EPSILON_DB - 20 * filterOrder));
    assertThat("high-pass pass-band ripple", getRange(magHighPass, (int) (N_SAMPLES_FFT * 0.95), N_SAMPLES_FFT), lessThan(ALLOWED_IN_BAND_RIPPLE_DB + EPSILON_DB));
}
 
Example #10
Source File: BeanFactoryIntegrationTests.java    From vividus with Apache License 2.0 6 votes vote down vote up
@ParameterizedTest
@CsvSource({
        "${profile-to-use}, basicenv,               integration",
        "basicprofile,      ${environments-to-use}, integration",
        "basicprofile,      basicenv,               ${suite-to-use}"
})
void shouldResolvePlaceholdersInConfigurationProperties(String profile, String environments, String suite)
        throws IOException
{
    System.setProperty(CONFIGURATION_PROFILE, profile);
    System.setProperty(CONFIGURATION_ENVIRONMENTS, environments);
    System.setProperty(CONFIGURATION_SUITE, suite);
    BeanFactory.open();
    assertProperties(null, null);
    assertIntegrationSuiteProperty();
}
 
Example #11
Source File: DateExpressionProcessorTests.java    From vividus with Apache License 2.0 6 votes vote down vote up
@ParameterizedTest
@CsvSource(delimiter = ';', value = {
        "generateDate(P5Y1M10D);                    1905-02-11",
        "generateDate(P1Y1M1W, dd-MM-YYYY);         08-02-1901",
        "generateDate(PT1H2M3S);                    1900-01-01T01:02:03",
        "generateDate(PT61M63S, YYYY'T'HH-mm-ss);   1900T01-02-03",
        "generateDate(-P1MT1M);                     1899-11-30T23:59:00",
        "generateDate(P, MMM);                      Jan",
        "generateDate(P, MMMM);                     January",
        "generateDate(P, d);                        1",
        "generateDate(P, EEE);                      Mon",
        "generateDate(P, EEEE);                     Monday",
        "generateDate(P, yyyy-MM-dd'T'HH:mm:ssZ);   1900-01-01T00:00:00+0000"
})
void testCalculatePeriod(String expression, String expected)
{
    mockGetCurrentDate();
    String actual = dateExpressionProcessor.execute(expression).get();
    assertEquals(expected, actual);
    assertThat(logger.getLoggingEvents(), equalTo(List.of()));
}
 
Example #12
Source File: HttpRequestStepsTests.java    From vividus with Apache License 2.0 6 votes vote down vote up
@ParameterizedTest
@CsvSource({
        // CHECKSTYLE:OFF
        "'|name|type|value|\n|partName|STRING|content|',                                      text/plain; charset=ISO-8859-1",
        "'|name|type|value|contentType|\n|partName|STRING|content|text/html; charset=utf-8|', text/html; charset=utf-8"
        // CHECKSTYLE:ON
})
void testPutMultipartRequest(String tableAsString, String contentType)
{
    ExamplesTable requestParts = new ExamplesTable(tableAsString);
    httpRequestSteps.putMultipartRequest(requestParts);
    verify(httpTestContext).putRequestEntity(argThat(entity ->
    {
        try
        {
            return IOUtils.toString(entity.getContent(), StandardCharsets.UTF_8)
                    .contains("Content-Disposition: form-data; name=\"partName\"" + CR_LF
                            + "Content-Type: " + contentType + CR_LF
                            + "Content-Transfer-Encoding: 8bit" + CR_LF + CR_LF + CONTENT + CR_LF);
        }
        catch (@SuppressWarnings("unused") IOException e)
        {
            return false;
        }
    }));
}
 
Example #13
Source File: IirFilterTests.java    From chart-fx with Apache License 2.0 6 votes vote down vote up
@DisplayName("ChebyshevI - Low-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 testChebyshevILowPass(final int filterOrder, final int algorithmVariant) {
    final ChebyshevI iirLowPass = new ChebyshevI();
    switch (algorithmVariant) {
    case 1:
        iirLowPass.lowPass(filterOrder, 1.0, F_CUT_LOW, ALLOWED_IN_BAND_RIPPLE_DB, DirectFormAbstract.DIRECT_FORM_I);
        break;
    case 2:
        iirLowPass.lowPass(filterOrder, 1.0, F_CUT_LOW, ALLOWED_IN_BAND_RIPPLE_DB, DirectFormAbstract.DIRECT_FORM_II);
        break;
    case 0:
    default:
        iirLowPass.lowPass(filterOrder, 1.0, F_CUT_LOW, ALLOWED_IN_BAND_RIPPLE_DB);
        break;
    }
    final DataSet magLowPass = filterAndGetMagnitudeSpectrum(iirLowPass, demoDataSet);
    assertThat("low-pass cut-off", magLowPass.getValue(DIM_X, F_CUT_LOW), lessThan(-3.0 + EPSILON_DB));
    assertThat("low-pass rejection", magLowPass.getValue(DIM_X, 10 * F_CUT_LOW), lessThan(-3.0 + EPSILON_DB - 20 * filterOrder));
    assertThat("low-pass pass-band ripple", getRange(magLowPass, 0, magLowPass.getIndex(DIM_X, F_CUT_LOW * 0.1)), lessThan(ALLOWED_IN_BAND_RIPPLE_DB + EPSILON_DB));
}
 
Example #14
Source File: RemoveWrappingDoubleQuotesExpressionProcessorTests.java    From vividus with Apache License 2.0 6 votes vote down vote up
@ParameterizedTest(name = "{index}: for expression \"{0}\", result is \"{1}\"")
@CsvSource({
    "removeWrappingDoubleQuotes(\"value\"),     value",
    "removeWrappingDoubleQuotes(value),         value",
    "removeWrappingDoubleQuotes(),              ''",
    "removeWrappingDoubleQuotes(\"\"),          ''",
    "removeWrappingDoubleQuotes(\"\"\"),        \"",
    "removeWrappingDoubleQuotes(\"value),       \"value",
    "removeWrappingDoubleQuotes(v\"alu\"e),     v\"alu\"e",
    "removeWrappingDoubleQuotes(\"va\"lu\"e\"), va\"lu\"e",
    "removeWrappingDoubleQuotes(\"va\"lu\"e),   \"va\"lu\"e",
    "removeWrappingDoubleQuotes(\"va\"lue),     \"va\"lue",
    "removeWrappingDoubleQuotes(va\"lue\"),     va\"lue\"",
    "RemoveWrappingdOUBLEQuotes(\"value\"),     value",
    "RemoveWrappingdOUBLEQuotes(\"value),       \"value",
    "removeWrappingDoubleQuotes(), ''"
    })
void testExecute(String expression, String expected)
{
    assertEquals(expected, processor.execute(expression).get());
}
 
Example #15
Source File: UtilityTest.java    From hedera-mirror-node with Apache License 2.0 6 votes vote down vote up
@ParameterizedTest(name = "with seconds {0} and nanos {1}")
@CsvSource({
        "1569936354, 901",
        "0, 901",
        "1569936354, 0",
        "0,0"
})
public void timeStampInNanosTimeStamp(long seconds, int nanos) {
    Timestamp timestamp = Timestamp.newBuilder().setSeconds(seconds).setNanos(nanos).build();

    long timeStampInNanos = Utility.timeStampInNanos(timestamp);
    Instant fromTimeStamp = Instant.ofEpochSecond(0, timeStampInNanos);

    assertAll(
            () -> assertEquals(timestamp.getSeconds(), fromTimeStamp.getEpochSecond())
            , () -> assertEquals(timestamp.getNanos(), fromTimeStamp.getNano())
    );
}
 
Example #16
Source File: TextFormatterTest.java    From PGM with GNU Affero General Public License v3.0 6 votes vote down vote up
@ParameterizedTest
@CsvSource(
    value = {
      "0;''",
      "1;alice",
      "2;alice and bob",
      "3;alice, bob, and jerry",
      "4;alice, bob, jerry, and nancy"
    },
    delimiter = ';')
void testList(int size, String expected) {
  final List<String> people = ImmutableList.of("alice", "bob", "jerry", "nancy");

  final List<Component> text = new LinkedList<>();
  for (String person : people.subList(0, size)) {
    text.add(TextComponent.of(person));
  }
  final Component actual = TextTranslations.translate(list(text, TextColor.WHITE), Locale.US);

  assertEquals(expected, PlainComponentSerializer.INSTANCE.serialize(actual));
}
 
Example #17
Source File: CommonParserPropertiesTest.java    From hedera-mirror-node with Apache License 2.0 6 votes vote down vote up
@DisplayName("Filter using exclude")
@ParameterizedTest(name = "with entity {0} and type {1} resulting in {2}")
@CsvSource({
        "0.0.1, CONSENSUSSUBMITMESSAGE, false",
        "0.0.2, CRYPTOCREATEACCOUNT, false",
        "0.0.3, FREEZE, false",
        "0.0.4, FILECREATE, false",
        "0.0.1, CRYPTOCREATEACCOUNT, true",
        "0.0.2, CONSENSUSSUBMITMESSAGE, true",
        "0.0.4, FREEZE, true",
        ", CONSENSUSSUBMITMESSAGE, true",
        "0.0.1, UNKNOWN, true",
        ", UNKNOWN, true"
})
void filterExclude(String entityId, TransactionTypeEnum type, boolean result) {
    commonParserProperties.getExclude().add(filter("0.0.1", TransactionTypeEnum.CONSENSUSSUBMITMESSAGE));
    commonParserProperties.getExclude().add(filter("0.0.2", TransactionTypeEnum.CRYPTOCREATEACCOUNT));
    commonParserProperties.getExclude().add(filter("0.0.3", null));
    commonParserProperties.getExclude().add(filter(null, TransactionTypeEnum.FILECREATE));

    assertEquals(result, commonParserProperties.getFilter().test(
            new TransactionFilterFields(entity(entityId), type)));
}
 
Example #18
Source File: CommonParserPropertiesTest.java    From hedera-mirror-node with Apache License 2.0 6 votes vote down vote up
@DisplayName("Filter using include")
@ParameterizedTest(name = "with entity {0} and type {1} resulting in {2}")
@CsvSource({
        "0.0.1, CONSENSUSSUBMITMESSAGE, true",
        "0.0.2, CRYPTOCREATEACCOUNT, true",
        "0.0.3, FREEZE, true",
        "0.0.4, FILECREATE, true",
        "0.0.1, CRYPTOCREATEACCOUNT, false",
        "0.0.2, CONSENSUSSUBMITMESSAGE, false",
        "0.0.4, FREEZE, false",
        ", CONSENSUSSUBMITMESSAGE, false",
        "0.0.1, UNKNOWN, false",
        ", UNKNOWN, false"
})
void filterInclude(String entityId, TransactionTypeEnum type, boolean result) {
    commonParserProperties.getInclude().add(filter("0.0.1", TransactionTypeEnum.CONSENSUSSUBMITMESSAGE));
    commonParserProperties.getInclude().add(filter("0.0.2", TransactionTypeEnum.CRYPTOCREATEACCOUNT));
    commonParserProperties.getInclude().add(filter("0.0.3", null));
    commonParserProperties.getInclude().add(filter(null, TransactionTypeEnum.FILECREATE));

    assertEquals(result, commonParserProperties.getFilter().test(
            new TransactionFilterFields(entity(entityId), type)));
}
 
Example #19
Source File: EntityRecordItemListenerFileTest.java    From hedera-mirror-node with Apache License 2.0 6 votes vote down vote up
@ParameterizedTest(name = "with {0} s and expected {1} ns")
@CsvSource({
        "9223372036854775807, 9223372036854775807",
        "31556889864403199, 9223372036854775807",
        "-9223372036854775808, -9223372036854775808",
        "-1000000000000000000, -9223372036854775808"
})
void fileCreateExpirationTimeOverflow(long seconds, long expectedNanosTimestamp) throws Exception {
    Transaction transaction = fileCreateTransaction(Timestamp.newBuilder().setSeconds(seconds).build());
    TransactionBody transactionBody = TransactionBody.parseFrom(transaction.getBodyBytes());
    TransactionRecord record = transactionRecord(transactionBody);

    parseRecordItemAndCommit(new RecordItem(transaction, record));

    var dbAccountEntity = getTransactionEntity(record.getConsensusTimestamp());
    assertEquals(expectedNanosTimestamp, dbAccountEntity.getExpiryTimeNs());
}
 
Example #20
Source File: EntityRecordItemListenerTopicTest.java    From hedera-mirror-node with Apache License 2.0 6 votes vote down vote up
@ParameterizedTest
@CsvSource({
        "0.0.65537, 10, 20, admin-key, submit-key, '', 1000000, 1, 30",
        "0.0.2147483647, 9223372036854775807, 2147483647, admin-key, '', memo, 1000001, 1, 30",
        "0.0.1, -9223372036854775808, -2147483648, '', '', memo, 1000002, , ,",
        "0.0.55, 10, 20, admin-key, submit-key, memo, 1000003, 1, 30"
})
void createTopicTest(@ConvertWith(TopicIdConverter.class) TopicID topicId, long expirationTimeSeconds,
                     int expirationTimeNanos, @ConvertWith(KeyConverter.class) Key adminKey,
                     @ConvertWith(KeyConverter.class) Key submitKey, String memo, long consensusTimestamp,
                     Long autoRenewAccountNum, Long autoRenewPeriod) throws Exception {
    var responseCode = ResponseCodeEnum.SUCCESS;
    var transaction = createCreateTopicTransaction(adminKey, submitKey, memo, autoRenewAccountNum, autoRenewPeriod);
    var transactionRecord = createTransactionRecord(topicId, consensusTimestamp, responseCode);

    parseRecordItemAndCommit(new RecordItem(transaction, transactionRecord));

    long entityCount = autoRenewAccountNum != null ? 4 : 3; // Node, payer, topic & optionally autorenew
    var entity = getTopicEntity(topicId);
    assertTransactionInRepository(responseCode, consensusTimestamp, entity.getId());
    assertEquals(entityCount, entityRepository.count());
    var expectedEntity = createTopicEntity(topicId, null, null, adminKey, submitKey, memo, autoRenewAccountNum,
            autoRenewPeriod);
    assertThat(entity).isEqualTo(expectedEntity);
}
 
Example #21
Source File: IirFilterTests.java    From chart-fx with Apache License 2.0 6 votes vote down vote up
@DisplayName("Bessel - Low-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 testBesselLowPass(final int filterOrder, final int algorithmVariant) {
    final Bessel iirLowPass = new Bessel();
    switch (algorithmVariant) {
    case 1:
        iirLowPass.lowPass(filterOrder, 1.0, F_CUT_LOW, DirectFormAbstract.DIRECT_FORM_I);
        break;
    case 2:
        iirLowPass.lowPass(filterOrder, 1.0, F_CUT_LOW, DirectFormAbstract.DIRECT_FORM_II);
        break;
    case 0:
    default:
        iirLowPass.lowPass(filterOrder, 1.0, F_CUT_LOW);
        break;
    }
    final DataSet magLowPass = filterAndGetMagnitudeSpectrum(iirLowPass, demoDataSet);
    assertThat("low-pass cut-off", magLowPass.getValue(DIM_X, F_CUT_LOW), lessThan(EPSILON_DB));
    assertThat("low-pass rejection", magLowPass.getValue(DIM_X, 10 * F_CUT_LOW), lessThan(-3.0 + EPSILON_DB - 10 * filterOrder));
    assertThat("low-pass pass-band ripple", getRange(magLowPass, 0, magLowPass.getIndex(DIM_X, F_CUT_LOW * 0.1)), lessThan(EPSILON_DB));
}
 
Example #22
Source File: ExpressionAdapterTests.java    From vividus with Apache License 2.0 6 votes vote down vote up
@ParameterizedTest
@CsvSource({
    "'target',         '#{target}',                                %s,             " + EXPRESSION_RESULT,
    "'target',         '{#{target}}',                              {%s},           " + EXPRESSION_RESULT,
    "'target',         '{#{target} and #{target}}',                {%1$s and %1$s}," + EXPRESSION_RESULT,
    "'target(})',      '#{target(})}',                             %s,             " + EXPRESSION_RESULT,
    "'tar\nget',       '#{tar\nget}',                              %s,             " + EXPRESSION_RESULT,
    "'expr(value{1})', '#{expr(#{expr(#{expr(value{1})})})}',      %s,                 value{1}"
})
void testSupportedExpression(String expressionKeyword, String input, String outputFormat, String outputValue)
{
    Mockito.lenient().when(mockedTargetProcessor.execute(EXPRESSION_KEYWORD))
            .thenReturn(Optional.of(EXPRESSION_RESULT));
    expressionAdaptor.setProcessors(List.of(mockedTargetProcessor, mockedAnotherProcessor));
    when(mockedTargetProcessor.execute(expressionKeyword)).thenReturn(Optional.of(outputValue));
    String actual = expressionAdaptor.process(input);
    String output = String.format(outputFormat, outputValue);
    assertEquals(output, actual);
}
 
Example #23
Source File: IirFilterTests.java    From chart-fx with Apache License 2.0 5 votes vote down vote up
@DisplayName("ChebyshevI - 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 testChebyshevIBandStop(final int filterOrder, final int algorithmVariant) {
    final ChebyshevI iirBandStop = new ChebyshevI();
    switch (algorithmVariant) {
    case 1:
        iirBandStop.bandStop(filterOrder, 1.0, F_BAND_CENTRE, F_BAND_WIDTH, ALLOWED_IN_BAND_RIPPLE_DB, DirectFormAbstract.DIRECT_FORM_I);
        break;
    case 2:
        iirBandStop.bandStop(filterOrder, 1.0, F_BAND_CENTRE, F_BAND_WIDTH, ALLOWED_IN_BAND_RIPPLE_DB, DirectFormAbstract.DIRECT_FORM_II);
        break;
    case 0:
    default:
        iirBandStop.bandStop(filterOrder, 1.0, F_BAND_CENTRE, F_BAND_WIDTH, ALLOWED_IN_BAND_RIPPLE_DB);
        break;
    }

    final DataSet magBandStop = filterAndGetMagnitudeSpectrum(iirBandStop, demoDataSet);
    assertThat("band-stop cut-off (low)", magBandStop.getValue(DIM_X, F_BAND_START), lessThan(-3.0 + EPSILON_DB));
    assertThat("band-stop cut-off (high)", magBandStop.getValue(DIM_X, F_BAND_STOP), lessThan(-3.0 + EPSILON_DB));
    assertThat("band-pass pass-band (low)", getRange(magBandStop, 0, magBandStop.getIndex(DIM_X, F_BAND_START * 0.1)), lessThan(ALLOWED_IN_BAND_RIPPLE_DB + EPSILON_DB));
    assertThat("band-pass pass-band (high)", getRange(magBandStop, (int) (N_SAMPLES_FFT * 0.95), N_SAMPLES_FFT), lessThan(ALLOWED_IN_BAND_RIPPLE_DB + 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 - 20 * filterOrder));
}
 
Example #24
Source File: LongToInstantConverterTest.java    From hedera-mirror-node with Apache License 2.0 5 votes vote down vote up
@DisplayName("Convert Long to Instant")
@ParameterizedTest(name = "with input {0} and output {1}")
@CsvSource({
        ",",
        "1564433324226490001, 2019-07-29T20:48:44.226490001Z",
        "1564433324000000000, 2019-07-29T20:48:44Z",
        "1, 1970-01-01T00:00:00.000000001Z"
})
void testConvert(Long input, Instant expected) {
    Instant result = converter.convert(input);
    Assertions.assertEquals(expected, result);
}
 
Example #25
Source File: Neo4jTransactionUtilsTest.java    From sdn-rx with Apache License 2.0 5 votes vote down vote up
@ParameterizedTest
@CsvSource({
	"a,",
	",b",
	"a,b"
})
void nameComparisionShouldWorkForNamesTargetingOther(String name1, String name2) {

	assertThat(namesMapToTheSameDatabase(name1, name2)).isFalse();
}
 
Example #26
Source File: DetectionTestCase.java    From jstarcraft-nlp with Apache License 2.0 5 votes vote down vote up
/**
 * 测试装载语种检测词典
 * 
 * @param path
 * @param size
 */
@ParameterizedTest
@CsvSource({ "dictionary-82.json,4", "dictionary-187.json,7", "dictionary-406.json,10" })
public void testLoadTrie(String path, int size) {
    try (InputStream stream = DetectionTrie.class.getResourceAsStream(path)) {
        Map<String, Set<DetectionTrie>> dictionaries = DetectionTrie.loadTries(stream);
        Assertions.assertEquals(size, dictionaries.size());
    } catch (Exception exception) {
        throw new IllegalArgumentException(exception);
    }
}
 
Example #27
Source File: DetectionTestCase.java    From jstarcraft-nlp with Apache License 2.0 5 votes vote down vote up
/**
 * 测试装载语种检测规则
 * 
 * @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);
    }
}
 
Example #28
Source File: EntityIdEndecTest.java    From hedera-mirror-node with Apache License 2.0 5 votes vote down vote up
@ParameterizedTest
@CsvSource({
        "0, 0, 0, 0",
        "0, 0, 10, 10",
        "0, 0, 4294967295, 4294967295",
        "10, 10, 10, 2814792716779530",
        "32767, 65535, 4294967295, 9223372036854775807", // max +ve for shard, max for realm, max for num = max +ve long
        "32767, 0, 0, 9223090561878065152"
})
void testEntityEncoding(long shard, long realm, long num, long encodedId) {
    assertThat(EntityIdEndec.encode(shard, realm, num)).isEqualTo(encodedId);
}
 
Example #29
Source File: ResolvingSelfReferencesEagerlyTransformerTests.java    From vividus with Apache License 2.0 5 votes vote down vote up
@ParameterizedTest
@CsvSource({
        "'|A|B|C|\n|a|<A>|c|',                     '|A|B|C|\n|a|a|c|'",
        "'|A|B|C|\n|a1|<A>|c1|\n|a2|<A>|c2|',      '|A|B|C|\n|a1|a1|c1|\n|a2|a2|c2|'",
        "'|A|B|C|D|E|F|\n|<C>|<A>|c|<F>|<D>|<B>|', '|A|B|C|D|E|F|\n|c|c|c|c|c|c|'",
        "'|A|B|C|\n|a|<A><C>|c|',                  '|A|B|C|\n|a|ac|c|'",
        "'|A|B|C|\n|a<p>|<p><A>|c|',               '|A|B|C|\n|a<p>|<p>a<p>|c|'",
        "'|A|B|C|\n|a|<A>|',                       '|A|B|C|\n|a|a|'",
        "'|A|B|\n|a|<A>|c|',                       '|A|B|\n|a|a|'",
        "'|A|B|C|\n|a|<<A>>|c|',                   '|A|B|C|\n|a|<<A>>|c|'"
})
void shouldTransform(String beforeTransform, String expectedResult)
{
    assertEquals(expectedResult, transform(beforeTransform));
}
 
Example #30
Source File: IirFilterTests.java    From chart-fx with Apache License 2.0 5 votes vote down vote up
@DisplayName("Bessel - Band-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 testBesselBandPass(final int filterOrder, final int algorithmVariant) {
    final Bessel iirBandPass = new Bessel();
    switch (algorithmVariant) {
    case 1:
        iirBandPass.bandPass(filterOrder, 1.0, F_BAND_CENTRE, F_BAND_WIDTH, DirectFormAbstract.DIRECT_FORM_I);
        break;
    case 2:
        iirBandPass.bandPass(filterOrder, 1.0, F_BAND_CENTRE, F_BAND_WIDTH, DirectFormAbstract.DIRECT_FORM_II);
        break;
    case 0:
    default:
        iirBandPass.bandPass(filterOrder, 1.0, F_BAND_CENTRE, F_BAND_WIDTH);
        break;
    }

    final DataSet magBandPass = filterAndGetMagnitudeSpectrum(iirBandPass, demoDataSet);
    assertThat("band-pass cut-off (low)", magBandPass.getValue(DIM_X, F_BAND_START), lessThan(EPSILON_DB));
    assertThat("band-pass cut-off (high)", magBandPass.getValue(DIM_X, F_BAND_STOP), lessThan(EPSILON_DB));
    assertThat("band-pass rejection (low)", magBandPass.getValue(DIM_X, 0.1 * F_BAND_START), lessThan(3.0 + EPSILON_DB - 10 * filterOrder));
    assertThat("band-pass rejection (high)", magBandPass.getValue(DIM_X, 10 * F_BAND_STOP), lessThan(3.0 + EPSILON_DB - 10 * filterOrder));
    final double rangePassBand = getRange(magBandPass,
            magBandPass.getIndex(DIM_X, (F_BAND_CENTRE - 0.1 * F_BAND_WIDTH)),
            magBandPass.getIndex(DIM_X, (F_BAND_CENTRE + 0.1 * F_BAND_WIDTH)));
    assertThat("band-pass pass-band ripple", rangePassBand, lessThan(10 * EPSILON_DB));
}