Package org.waveprotocol.wave.model.document.bootstrap

Examples of org.waveprotocol.wave.model.document.bootstrap.BootstrapDocument


  public void testRandomDocOps() throws OperationException {
    OpEquator eq = OpComparators.SYNTACTIC_IDENTITY;

    Parameters p = new Parameters();
    for (int i = 0; i < 200; i++) {
      BootstrapDocument doc = new BootstrapDocument();
      for (int j = 0; j < 20; j++) {
        RandomProvider ra = RandomProviderImpl.ofSeed(i * 20 + j);
        RandomProvider rb = RandomProviderImpl.ofSeed(i * 20 + j + 1);
        DocOp a = RandomDocOpGenerator.generate(ra, p, doc);
        DocOp b = RandomDocOpGenerator.generate(rb, p, doc);
        doc.consume(a);
        assertTrue(eq.equal(a, a));
        // The combination of RandomProvider and RandomDocOpGenerator doesn't
        // really guarantee this property, but it happens to be true with the
        // random seeds that occur here.
        assertFalse(eq.equal(a, b));
View Full Code Here


public class DocumentDomain implements Domain<BootstrapDocument, DocOp> {

  @Override
  public BootstrapDocument initialState() {
    return new BootstrapDocument();
  }
View Full Code Here

  public void testEquivalence() throws OperationException, TransformException {
    Random r = new Random(0);
    DocOpGenerator generator = new DocOpGenerator();
    for (int iteration = 0; iteration < NUM_ITERATIONS; ++iteration) {
      System.out.println("Iteration: " + iteration);
      BootstrapDocument document= new BootstrapDocument();
      for (int i = 0; i < INITIAL_MUTATION_COUNT; ++i) {
        document.consume(generator.randomOperation(document, r));
      }
      for (int i = 0; i < FEATURE_ITERATION_COUNT; ++i) {
        DocOp clientOp = generator.randomOperation(document, r);
        DocOp serverOp = generator.randomOperation(document, r);
        OperationPair<DocOp> pair = Transformer.transform(clientOp, serverOp);
        OperationPair<DocOp> referencePair =
            ReferenceTransformer.transform(clientOp, serverOp);
        assertTrue(OpComparators.SYNTACTIC_IDENTITY.equal(
            pair.clientOp(), referencePair.clientOp()));
        assertTrue(OpComparators.SYNTACTIC_IDENTITY.equal(
            pair.serverOp(), referencePair.serverOp()));
        document.consume(clientOp);
        document.consume(pair.serverOp());
      }
    }
  }
View Full Code Here

  void doTest(TestData t) throws OperationException {
    DocOpBuffer d = new DocOpBuffer();
    DocOpBuffer m = new DocOpBuffer();
    boolean expected = t.build(d, m);

    BootstrapDocument doc = new BootstrapDocument();

    // initialize document
    doc.consume(d.finishUnchecked());

    // check whether m would apply
    ViolationCollector v = new ViolationCollector();
    ValidationResult result =
        DocOpValidator.validate(v, t.getSchemaConstraints(), doc, m.finishUnchecked());
View Full Code Here

    AutomatonDocument checkAuto;

    // Set to false for faster test runs
    boolean checkAgainstBootstrapDocument = true;
    if (checkAgainstBootstrapDocument) {
      BootstrapDocument bootstrapDoc = new BootstrapDocument();
      checkDocOpProvider = bootstrapDoc;
      checkDoc = bootstrapDoc;
      checkAuto = bootstrapDoc;
    } else {
      IndexedDocument<Node, Element, Text> indexedDoc = DocProviders.POJO.parse("");
      checkDocOpProvider = indexedDoc;
      checkDoc = indexedDoc;
      checkAuto = Automatons.fromReadable(indexedDoc);
    }

    for (int i = 0; i < NUM_INITIAL_MUTATIONS; i++) {
      DocOp op = RandomDocOpGenerator.generate(random, params,
          // FIXME(ohler): Add back schema constraints
          // DocumentOperationValidator.DEFAULT_BLIP_SCHEMA_CONSTRAINTS,
          autoDoc);
      doc.consume(op);
      checkDoc.consume(op);
    }

    String originalXml = DocOpUtil.toXmlString(doc.asOperation());

    for (int i = 0; i < NUM_REVERSED_MUTATIONS_PER_RUN; i++) {

      // Apply random mutation and revert it.
      DocOp op = RandomDocOpGenerator.generate(random, params,
          // FIXME(ohler): Add back schema constraints
          // DocumentOperationValidator.DEFAULT_BLIP_SCHEMA_CONSTRAINTS,
          autoDoc);

      Nindo nindo = null;
      String finalXml = null;
      DocOp docOpCopy = null;
      DocInitialization docAsOp = null;

      try {

        //System.out.println("  " + i);
        //System.out.println("\n===" + iteration + "." + i + "===============================");

        docAsOp = doc.asOperation();
        validate(DocOpAutomaton.EMPTY_DOCUMENT, docAsOp);
        IndexedDocument<Node, Element, Text> copy = DocProviders.POJO.build(docAsOp,
            DocumentSchema.NO_SCHEMA_CONSTRAINTS);
        BootstrapDocument copy2 = new BootstrapDocument();
        copy2.consume(docAsOp);

        // CONSUME
        doc.consume(op);
        checkDoc.consume(op);

        finalXml = DocOpUtil.toXmlString(checkDocOpProvider.asOperation());

        assertEquals(finalXml, DocOpUtil.toXmlString(doc.asOperation()));

        // UNDO
        DocOp inverted1 = DocOpInverter.invert(op);
        validate(autoDoc, inverted1);
        doc.consume(inverted1);
        assertEquals(originalXml, DocOpUtil.toXmlString(doc.asOperation()));

        // CONSUME NINDO
        // TODO(danilatos): Both remove and don't remove the trailing skip, randomly
        nindo = Nindo.fromDocOp(op, true);
        docOpCopy = doc.consumeAndReturnInvertible(nindo);
        assertEquals(finalXml, DocOpUtil.toXmlString(doc.asOperation()));

        validate(Automatons.fromReadable(copy), docOpCopy);
        validate(copy2, docOpCopy);
        copy2.consume(docOpCopy);
        assertEquals(finalXml, DocOpUtil.toXmlString(copy2.asOperation()));

        // UNDO NINDO
        DocOp inverted2 = DocOpInverter.invert(docOpCopy);
        validate(checkAuto, inverted2);
        validate(autoDoc, inverted2);
View Full Code Here

  /**
   * Stand-alone main() for quick experimentation.
   */
  public static void main(String[] args) throws OperationException {
    BootstrapDocument initialDoc = new BootstrapDocument();
    initialDoc.consume(new DocInitializationBuilder()
        .elementStart("blip", Attributes.EMPTY_MAP)
        .elementStart("p", Attributes.EMPTY_MAP)
        .characters("abc")
        .elementEnd()
        .elementEnd().build());

    Parameters p = new Parameters();

    p.setMaxOpeningComponents(10);

    RandomProvider r = RandomProviderImpl.ofSeed(2538);
    for (int i = 0; i < 200; i++) {
      BootstrapDocument doc = new BootstrapDocument();
      doc.consume(initialDoc.asOperation());
      for (int j = 0; j < 20; j++) {
        System.err.println("i=" + i + ", j=" + j);
        System.err.println("old: " + DocOpUtil.toXmlString(doc.asOperation()));
        System.err.println("old: " + DocOpUtil.toConciseString(doc.asOperation()));
        DocOp op = generate(r, p, doc);
        System.err.println("op:  " + DocOpUtil.toConciseString(op));
        doc.consume(op);
        System.err.println("new: " + DocOpUtil.toConciseString(doc.asOperation()));
        System.err.println("new: " + DocOpUtil.toXmlString(doc.asOperation()));
        if (!DocOpValidator.validate(null, DocumentSchema.NO_SCHEMA_CONSTRAINTS,
            doc.asOperation()).isValid()) {
          throw new RuntimeException("doc not valid");
        }
      }
    }
  }
View Full Code Here

  /**
   * Stand-alone main() for quick experimentation.
   */
  public static void main(String[] args) throws OperationException {
    BootstrapDocument initialDoc = new BootstrapDocument();
    initialDoc.consume(new DocInitializationBuilder()
        .elementStart("blip", Attributes.EMPTY_MAP)
        .elementStart("p", Attributes.EMPTY_MAP)
        .characters("abc")
        .elementEnd()
        .elementEnd().build());

    Parameters p = new Parameters();

    p.setMaxOpeningComponents(10);

    RandomProvider r = RandomProviderImpl.ofSeed(2538);
    for (int i = 0; i < 200; i++) {
      BootstrapDocument doc = new BootstrapDocument();
      doc.consume(initialDoc.asOperation());
      for (int j = 0; j < 20; j++) {
        System.err.println("i=" + i + ", j=" + j);
        System.err.println("old: " + DocOpUtil.toXmlString(doc.asOperation()));
        System.err.println("old: " + DocOpUtil.toConciseString(doc.asOperation()));
        DocOp op = generate(r, p, doc);
        System.err.println("op:  " + DocOpUtil.toConciseString(op));
        doc.consume(op);
        System.err.println("new: " + DocOpUtil.toConciseString(doc.asOperation()));
        System.err.println("new: " + DocOpUtil.toXmlString(doc.asOperation()));
        if (!DocOpValidator.validate(null, DocumentSchema.NO_SCHEMA_CONSTRAINTS,
            doc.asOperation()).isValid()) {
          throw new RuntimeException("doc not valid");
        }
      }
    }
  }
View Full Code Here

TOP

Related Classes of org.waveprotocol.wave.model.document.bootstrap.BootstrapDocument

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.