Search in sources :

Example 1 with ArgumentsSource

use of org.junit.jupiter.params.provider.ArgumentsSource in project siesta by cadenzauk.

the class DatabaseIntegrationTest method canRoundTripLocalTimes.

@ParameterizedTest
@ArgumentsSource(TestCaseArgumentsProvider.class)
@TestCase({ "America/Anchorage" })
@TestCase({ "America/Sao_Paulo" })
@TestCase({ "UTC" })
@TestCase({ "Europe/London" })
@TestCase({ "Africa/Johannesburg" })
@TestCase({ "Pacific/Chatham" })
void canRoundTripLocalTimes(String timeZone) {
    Database database = testDatabase(dataSource, dialect);
    try (UncheckedAutoCloseable ignored = withTimeZone(timeZone)) {
        LocalTime expected = randomLocalTime();
        TestRow input = TestRow.of(expected);
        database.insert(input);
        LocalTime result = database.from(TestRow.class).select(TestRow::localTimeOpt).where(TestRow::guid).isEqualTo(input.guid()).single();
        assertThat(result, is(expected));
    }
}
Also used : LocalTime(java.time.LocalTime) RandomValues.randomLocalTime(com.cadenzauk.core.RandomValues.randomLocalTime) TestRow(com.cadenzauk.siesta.model.TestRow) TestDatabase.testDatabase(com.cadenzauk.siesta.model.TestDatabase.testDatabase) UncheckedAutoCloseable(com.cadenzauk.core.lang.UncheckedAutoCloseable) TestCase(com.cadenzauk.core.junit.TestCase) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) ArgumentsSource(org.junit.jupiter.params.provider.ArgumentsSource)

Example 2 with ArgumentsSource

use of org.junit.jupiter.params.provider.ArgumentsSource in project siesta by cadenzauk.

the class DatabaseIntegrationTest method canRoundTripZonedDateTimes.

@ParameterizedTest
@ArgumentsSource(TestCaseArgumentsProvider.class)
@TestCase({ "America/Anchorage" })
@TestCase({ "America/Sao_Paulo" })
@TestCase({ "UTC" })
@TestCase({ "Europe/London" })
@TestCase({ "Africa/Johannesburg" })
@TestCase({ "Pacific/Chatham" })
void canRoundTripZonedDateTimes(String timeZone) {
    Database database = testDatabase(dataSource, dialect);
    try (UncheckedAutoCloseable ignored = withTimeZone(timeZone)) {
        ZonedDateTime expected = randomZonedDateTime(ZoneId.of("UTC"));
        TestRow input = TestRow.of(expected);
        database.insert(input);
        ZonedDateTime result = database.from(TestRow.class).select(TestRow::utcDateTimeOpt).where(TestRow::guid).isEqualTo(input.guid()).single();
        assertThat(result, is(expected));
    }
}
Also used : ZonedDateTime(java.time.ZonedDateTime) RandomValues.randomZonedDateTime(com.cadenzauk.core.RandomValues.randomZonedDateTime) TestRow(com.cadenzauk.siesta.model.TestRow) TestDatabase.testDatabase(com.cadenzauk.siesta.model.TestDatabase.testDatabase) UncheckedAutoCloseable(com.cadenzauk.core.lang.UncheckedAutoCloseable) TestCase(com.cadenzauk.core.junit.TestCase) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) ArgumentsSource(org.junit.jupiter.params.provider.ArgumentsSource)

Example 3 with ArgumentsSource

use of org.junit.jupiter.params.provider.ArgumentsSource in project solution-finder by knewjade.

the class CheckerNoHoldTest method testCaseList.

@ParameterizedTest
@ArgumentsSource(TestCase.class)
@LongTest
void testCaseList(Pieces pieces, boolean expectedCount) throws Exception {
    int maxDepth = 10;
    int maxClearLine = 4;
    Field field = FieldFactory.createField(maxClearLine);
    // Initialize
    Candidate<Action> candidate = new LockedCandidate(minoFactory, minoShifter, minoRotation, maxClearLine);
    LockedReachable reachable = new LockedReachable(minoFactory, minoShifter, minoRotation, maxClearLine);
    // Assertion
    // Set test case
    List<Piece> piecesList = pieces.getPieces();
    // Execute
    boolean isSucceed = checker.check(field, pieces, candidate, maxClearLine, maxDepth);
    assertThat(isSucceed).isEqualTo(expectedCount);
    // Check result
    if (isSucceed)
        assertResult(field, maxClearLine, reachable, piecesList);
}
Also used : Field(core.field.Field) LockedCandidate(core.action.candidate.LockedCandidate) Action(common.datastore.action.Action) Piece(core.mino.Piece) LockedReachable(core.action.reachable.LockedReachable) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) LongTest(module.LongTest) ArgumentsSource(org.junit.jupiter.params.provider.ArgumentsSource)

Example 4 with ArgumentsSource

use of org.junit.jupiter.params.provider.ArgumentsSource in project solution-finder by knewjade.

the class CheckmateNoHoldTest method testCaseList.

@ParameterizedTest
@ArgumentsSource(TestCase.class)
@LongTest
void testCaseList(Pieces pieces, int expectedCount) {
    // Field
    int maxClearLine = 4;
    int maxDepth = 10;
    Field field = FieldFactory.createField(maxClearLine);
    // Initialize
    Candidate<Action> candidate = new LockedCandidate(minoFactory, minoShifter, minoRotation, maxClearLine);
    LockedReachable reachable = new LockedReachable(minoFactory, minoShifter, minoRotation, maxClearLine);
    // Assertion
    // Set test case
    List<Piece> piecesList = pieces.getPieces();
    System.out.println(piecesList);
    // Execute
    List<Result> results = checkmate.search(field, piecesList, candidate, maxClearLine, maxDepth);
    assertThat(results).as(piecesList.toString()).hasSize(expectedCount);
    // Check result
    for (Result result : results) assertResult(result, field, maxClearLine, reachable, piecesList);
}
Also used : Field(core.field.Field) LockedCandidate(core.action.candidate.LockedCandidate) Action(common.datastore.action.Action) Piece(core.mino.Piece) LockedReachable(core.action.reachable.LockedReachable) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) LongTest(module.LongTest) ArgumentsSource(org.junit.jupiter.params.provider.ArgumentsSource)

Example 5 with ArgumentsSource

use of org.junit.jupiter.params.provider.ArgumentsSource in project solution-finder by knewjade.

the class CheckerNoHoldInvokerTest method testSearch3.

@ParameterizedTest
@ArgumentsSource(InvokerTestCase.class)
void testSearch3(IntFunction<ConcurrentCheckerInvoker> invokerGenerator) throws Exception {
    PatternGenerator blocksGenerator = new LoadedPatternGenerator("*p7");
    int maxClearLine = 4;
    int maxDepth = 7;
    String marks = "" + "X_________" + "X___X_____" + "XXXXXXX___" + "XXXXXX____" + "";
    // 結果を集計する
    ConcurrentCheckerInvoker invoker = invokerGenerator.apply(maxClearLine);
    AnalyzeTree tree = runTestCase(invoker, marks, blocksGenerator, maxClearLine, maxDepth);
    // Source: myself 20170415
    assertThat(tree.getSuccessPercent()).isEqualTo(727 / 5040.0);
}
Also used : PatternGenerator(common.pattern.PatternGenerator) LoadedPatternGenerator(common.pattern.LoadedPatternGenerator) LoadedPatternGenerator(common.pattern.LoadedPatternGenerator) AnalyzeTree(common.tree.AnalyzeTree) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) ArgumentsSource(org.junit.jupiter.params.provider.ArgumentsSource)

Aggregations

ArgumentsSource (org.junit.jupiter.params.provider.ArgumentsSource)50 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)49 LoadedPatternGenerator (common.pattern.LoadedPatternGenerator)27 PatternGenerator (common.pattern.PatternGenerator)27 AnalyzeTree (common.tree.AnalyzeTree)27 LongTest (module.LongTest)16 Log (_usecase.Log)10 TestCase (com.cadenzauk.core.junit.TestCase)7 TestDatabase.testDatabase (com.cadenzauk.siesta.model.TestDatabase.testDatabase)7 Action (common.datastore.action.Action)7 Field (core.field.Field)7 UncheckedAutoCloseable (com.cadenzauk.core.lang.UncheckedAutoCloseable)6 LockedCandidate (core.action.candidate.LockedCandidate)6 Piece (core.mino.Piece)5 LockedReachable (core.action.reachable.LockedReachable)4 RandomValues.randomZonedDateTime (com.cadenzauk.core.RandomValues.randomZonedDateTime)3 TestRow (com.cadenzauk.siesta.model.TestRow)3 MinoFactory (core.mino.MinoFactory)3 MinoShifter (core.mino.MinoShifter)3 MinoRotation (core.srs.MinoRotation)3