use of common.datastore.SimpleOperation in project solution-finder by knewjade.
the class OperationInterpreterTest method parseRandom.
@Test
void parseRandom() throws Exception {
Randoms randoms = new Randoms();
for (int size = 1; size < 20; size++) {
List<Operation> operationList = Stream.generate(() -> {
Piece piece = randoms.block();
Rotate rotate = randoms.rotate();
int x = randoms.nextInt(10);
int y = randoms.nextInt(4);
return new SimpleOperation(piece, rotate, x, y);
}).limit(size).collect(Collectors.toList());
Operations operations = new Operations(operationList);
String str = OperationInterpreter.parseToString(operations);
Operations actual = OperationInterpreter.parseToOperations(str);
assertThat(actual).isEqualTo(operations);
}
}
use of common.datastore.SimpleOperation in project solution-finder by knewjade.
the class OperationInterpreter method createOperation.
private static Operation createOperation(String strings) {
String[] split = strings.split(",");
assert split.length == 4;
Piece piece = StringEnumTransform.toPiece(split[0].trim());
Rotate rotate = StringEnumTransform.toRotate(split[1].trim());
int x = Integer.valueOf(split[2].trim());
int y = Integer.valueOf(split[3].trim());
return new SimpleOperation(piece, rotate, x, y);
}
use of common.datastore.SimpleOperation in project solution-finder by knewjade.
the class ActionParserTest method parseToOperation.
@Test
void parseToOperation() throws Exception {
for (Piece piece : Piece.values()) {
for (Rotate rotate : Rotate.values()) {
for (int y = 0; y < 24; y++) {
for (int x = 0; x < 10; x++) {
int value = ActionParser.parseToInt(piece, rotate, x, y);
assertThat(ActionParser.parseToOperation(value)).isEqualTo(new SimpleOperation(piece, rotate, x, y));
}
}
}
}
}
use of common.datastore.SimpleOperation in project solution-finder by knewjade.
the class OperationHistoryTest method random.
@Test
void random() throws ExecutionException, InterruptedException {
Randoms randoms = new Randoms();
for (int count = 0; count < 1000; count++) {
int size = randoms.nextInt(1, 10);
ArrayList<Operation> operations = new ArrayList<>();
OperationHistory history = new OperationHistory(size);
for (int index = 0; index < size; index++) {
Piece piece = randoms.block();
Rotate rotate = randoms.rotate();
int y = randoms.nextInt(4);
int x = randoms.nextInt(10);
MinimalAction action = MinimalAction.create(x, y, rotate);
history = history.recordAndReturnNew(piece, action);
operations.add(new SimpleOperation(piece, rotate, x, y));
}
List<Operation> actual = history.getOperationStream().collect(Collectors.toList());
assertThat(actual).isEqualTo(operations);
}
}
use of common.datastore.SimpleOperation in project solution-finder by knewjade.
the class OperationComparatorTest method compareDiffBlock.
@Test
void compareDiffBlock() throws Exception {
SimpleOperation operation1 = new SimpleOperation(Piece.S, Rotate.Spawn, 0, 1);
Operation operation2 = createNewOperation(Piece.J, Rotate.Spawn, 7, 1);
// assert is not 0 & sign reversed
OperationComparator comparator = new OperationComparator();
assertThat(comparator.compare(operation1, operation2) * comparator.compare(operation2, operation1)).isLessThan(0);
}
Aggregations