Search in sources :

Example 1 with SmallField

use of core.field.SmallField in project solution-finder by knewjade.

the class FieldComparatorTest method compare.

@Test
void compare() throws Exception {
    Randoms randoms = new Randoms();
    FieldComparator comparator = new FieldComparator();
    for (int count = 0; count < 10000; count++) {
        // same field
        int height = randoms.nextInt(1, 6);
        Field field1 = new SmallField();
        Field field2 = new MiddleField();
        int maxBlock = randoms.nextInt(1, 15);
        for (int block = 0; block < maxBlock; block++) {
            int x = randoms.nextInt(10);
            int y = randoms.nextInt(height);
            field1.setBlock(x, y);
            field2.setBlock(x, y);
        }
        assertThat(comparator.compare(field1, field2)).isEqualTo(0);
        assertThat(comparator.compare(field2, field1)).isEqualTo(0);
        // 1block different field
        int x = randoms.nextInt(10);
        int y = randoms.nextInt(height);
        if (field1.isEmpty(x, y))
            field1.setBlock(x, y);
        else
            field1.removeBlock(x, y);
        // assert is not 0 & reversed sign
        assertThat(comparator.compare(field1, field2) * comparator.compare(field2, field1)).isLessThan(0);
    }
}
Also used : SmallField(core.field.SmallField) Field(core.field.Field) MiddleField(core.field.MiddleField) Randoms(lib.Randoms) MiddleField(core.field.MiddleField) SmallField(core.field.SmallField) Test(org.junit.jupiter.api.Test)

Example 2 with SmallField

use of core.field.SmallField in project solution-finder by knewjade.

the class PieceFieldTest method mergeAndGet.

@Test
void mergeAndGet() throws Exception {
    int height = 4;
    BlockField blockField = new BlockField(height);
    Field field1 = FieldFactory.createField("" + "__X_______" + "_XXX______");
    blockField.merge(field1, Piece.T);
    Field field2 = FieldFactory.createField("" + "X_________" + "XX________" + "X_________");
    blockField.merge(field2, Piece.T);
    Field expected = FieldFactory.createField("" + "X_________" + "XXX_______" + "XXXX______");
    assertThat(blockField.get(Piece.T)).isEqualTo(expected);
    for (Piece piece : Arrays.asList(Piece.I, Piece.O, Piece.S, Piece.Z, Piece.L, Piece.J)) {
        Field field = new SmallField();
        assertThat(blockField.get(piece)).isEqualTo(field);
    }
}
Also used : SmallField(core.field.SmallField) Field(core.field.Field) Piece(core.mino.Piece) SmallField(core.field.SmallField) Test(org.junit.jupiter.api.Test)

Example 3 with SmallField

use of core.field.SmallField in project solution-finder by knewjade.

the class PercentTetfuCaseTest method useTetfuAndCommand3.

@Test
void useTetfuAndCommand3() throws Exception {
    // テト譜 (無関係なコメント付き) + パターンコマンド (パターンファイルを無視)
    /*
            comment: 1ページ目: 無関係なコメントです
            XX________
            XXX______X
            XXX_____XX
            XXXX_____X
             */
    String tetfu = "v115@9gB8HeC8FeD8EeF8EeA8JeAgWbBxXHDBQGDSA1d0AC?DYHDBQzuRA1Dq9BF4CwBFbcRA1zW9AxXXXB1RhRAV/d3ByX?HDBQxCSA1dUzBzXHDBwHfRA1d0ACzXHDBw0uRA1d0KB3XHD?Bwv4AA";
    ConfigFileHelper.createFieldFile(new SmallField(), 4);
    ConfigFileHelper.createPatternFile("*p7");
    String command = String.format("percent -c 4 -p *p7 -t %s", tetfu);
    Log log = RunnerHelper.runnerCatchingLog(() -> EntryPointMain.main(command.split(" ")));
    assertThat(log.getOutput()).contains(Messages.useHold()).contains(Messages.success(5008, 5040)).contains("*p7").contains(Messages.clearLine(4)).contains(Messages.patternSize(5040)).contains(Messages.treeHeadSize(3)).contains(Messages.tree("*", 99.37)).contains(Messages.tree("S", 98.33)).contains(Messages.tree("OS", 95.83)).contains(Messages.tree("ZOS", 83.33)).contains(Messages.failPatternSize(100)).doesNotContain(Messages.failNothing());
    assertThat(log.getError()).isEmpty();
}
Also used : Log(_usecase.Log) SmallField(core.field.SmallField) Test(org.junit.jupiter.api.Test) LongTest(module.LongTest)

Example 4 with SmallField

use of core.field.SmallField in project solution-finder by knewjade.

the class PercentTetfuCaseTest method useTetfuAndCommand4.

@Test
void useTetfuAndCommand4() throws Exception {
    // テト譜 (無関係なコメント付き) + パターンコマンド (パターンファイルを無視)
    /*
            comment: 日本語開始のコメント
            XXXXXX____
            XXXXXX____
            XXXXXX_X__
            XXXXXXXXX_
             */
    String tetfu = "v115@9gF8DeF8DeF8AeA8BeI8KeAgW8AlfrHBFwDfE2Cx2B?l/PwB5HEfE5fmzBlPJVBjDEfET4p9Blvs2ACtDfETor6Alv?s2AGtDfETIPSB";
    ConfigFileHelper.createFieldFile(new SmallField(), 4);
    ConfigFileHelper.createPatternFile("*p7");
    String command = String.format("percent -c 4 -p *p4 -t %s", tetfu);
    Log log = RunnerHelper.runnerCatchingLog(() -> EntryPointMain.main(command.split(" ")));
    assertThat(log.getOutput()).contains(Messages.useHold()).contains(Messages.softdrop()).contains(Messages.success(312, 840)).contains("*p4").contains(Messages.clearLine(4)).contains(Messages.patternSize(840)).contains(Messages.treeHeadSize(3)).contains(Messages.tree("*", 37.14)).contains(Messages.tree("I", 40.00)).contains(Messages.tree("OS", 5.0)).contains(Messages.tree("IOS", 0.0)).contains(Messages.failPatternSize(100)).doesNotContain(Messages.failNothing());
    assertThat(log.getError()).isEmpty();
}
Also used : Log(_usecase.Log) SmallField(core.field.SmallField) Test(org.junit.jupiter.api.Test) LongTest(module.LongTest)

Aggregations

SmallField (core.field.SmallField)4 Test (org.junit.jupiter.api.Test)4 Log (_usecase.Log)2 Field (core.field.Field)2 LongTest (module.LongTest)2 MiddleField (core.field.MiddleField)1 Piece (core.mino.Piece)1 Randoms (lib.Randoms)1