public function testApply()
 {
     $this->m->setDistance(1000);
     $this->m->setThreshold(0.5);
     $this->p->setDeleteTreshold(0.5);
     // Null case.
     $patches = $this->p->make("", "");
     $this->assertEquals(array("Hello world.", array()), $this->p->apply($patches, "Hello world."));
     // Exact match.
     $patches = $this->p->make("The quick brown fox jumps over the lazy dog.", "That quick brown fox jumped over a lazy dog.");
     $this->assertEquals(array("That quick brown fox jumped over a lazy dog.", array(true, true)), $this->p->apply($patches, "The quick brown fox jumps over the lazy dog."));
     // Partial match.
     $this->assertEquals(array("That quick red rabbit jumped over a tired tiger.", array(true, true)), $this->p->apply($patches, "The quick red rabbit jumps over the tired tiger."));
     // Failed match.
     $this->assertEquals(array("I am the very model of a modern major general.", array(false, false)), $this->p->apply($patches, "I am the very model of a modern major general."));
     // Big delete, small change.
     $patches = $this->p->make("x1234567890123456789012345678901234567890123456789012345678901234567890y", "xabcy");
     $this->assertEquals(array("xabcy", array(true, true)), $this->p->apply($patches, "x123456789012345678901234567890-----++++++++++-----123456789012345678901234567890y"));
     // Big delete, big change 1.
     $patches = $this->p->make("x1234567890123456789012345678901234567890123456789012345678901234567890y", "xabcy");
     $this->assertEquals(array("xabc12345678901234567890---------------++++++++++---------------12345678901234567890y", array(false, true)), $this->p->apply($patches, "x12345678901234567890---------------++++++++++---------------12345678901234567890y"));
     // Big delete, big change 2.
     $this->p->setDeleteTreshold(0.6);
     $patches = $this->p->make("x1234567890123456789012345678901234567890123456789012345678901234567890y", "xabcy");
     $this->assertEquals(array("xabcy", array(true, true)), $this->p->apply($patches, "x12345678901234567890---------------++++++++++---------------12345678901234567890y"));
     $this->p->setDeleteTreshold(0.5);
     // Compensate for failed patch.
     $this->m->setDistance(0);
     $this->m->setThreshold(0.0);
     $patches = $this->p->make("abcdefghijklmnopqrstuvwxyz--------------------1234567890", "abcXXXXXXXXXXdefghijklmnopqrstuvwxyz--------------------1234567YYYYYYYYYY890");
     $this->assertEquals(array("ABCDEFGHIJKLMNOPQRSTUVWXYZ--------------------1234567YYYYYYYYYY890", array(false, true)), $this->p->apply($patches, "ABCDEFGHIJKLMNOPQRSTUVWXYZ--------------------1234567890"));
     $this->m->setDistance(1000);
     $this->m->setThreshold(0.5);
     // No side effects.
     $patches = $this->p->make("", "test");
     $patchesText = $this->p->toText($patches);
     $this->p->apply($patches, "");
     $this->assertEquals($patchesText, $this->p->toText($patches));
     // No side effects with major delete.
     $patches = $this->p->make("The quick brown fox jumps over the lazy dog.", "Woof");
     $patchesText = $this->p->toText($patches);
     $this->p->apply($patches, "The quick brown fox jumps over the lazy dog.");
     $this->assertEquals($patchesText, $this->p->toText($patches));
     // Edge exact match.
     $patches = $this->p->make("", "test");
     $this->assertEquals(array("test", array(true)), $this->p->apply($patches, ""));
     // Near edge exact match.
     $patches = $this->p->make("XY", "XtestY");
     $this->assertEquals(array("XtestY", array(true)), $this->p->apply($patches, "XY"));
     // Edge partial match.
     $patches = $this->p->make("y", "y123");
     $this->assertEquals(array("x123", array(true)), $this->p->apply($patches, "x"));
 }
 /**
  * Take a list of patches and return a textual representation.
  *
  * @param PatchObject[] $patches Array of PatchObjects.
  *
  * @return string Text representation of patches.
  */
 public function patch_toText($patches)
 {
     return $this->patch->toText($patches);
 }