本文整理汇总了PHP中Match::setThreshold方法的典型用法代码示例。如果您正苦于以下问题:PHP Match::setThreshold方法的具体用法?PHP Match::setThreshold怎么用?PHP Match::setThreshold使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Match
的用法示例。
在下文中一共展示了Match::setThreshold方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __set
/**
* Proxy setting properties to real objects.
*
* @param string $name Property name.
* @param mixed $value Property value.
*
* @throws \UnexpectedValueException If property unknown.
* @return float
*/
public function __set($name, $value)
{
switch ($name) {
case 'Diff_Timeout':
$this->diff->setTimeout($value);
break;
case 'Diff_EditCost':
$this->diff->setEditCost($value);
break;
case 'Match_Threshold':
$this->match->setThreshold($value);
break;
case 'Match_Distance':
$this->match->setDistance($value);
break;
case 'Match_MaxBits':
$this->match->setMaxBits($value);
break;
case 'Patch_DeleteThreshold':
$this->patch->setDeleteTreshold($value);
break;
case 'Patch_Margin':
$this->patch->setMargin($value);
break;
default:
throw new \UnexpectedValueException('Unknown property: ' . $name);
}
}
示例2: testApply
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"));
}
示例3: testMain
public function testMain()
{
// Full match.
// Shortcut matches.
$this->assertEquals(0, $this->m->main("abcdef", "abcdef", 1000));
$this->assertEquals(-1, $this->m->main("", "abcdef", 1));
$this->assertEquals(3, $this->m->main("abcdef", "", 3));
$this->assertEquals(3, $this->m->main("abcdef", "de", 3));
$this->assertEquals(3, $this->m->main("abcdef", "defy", 4));
$this->assertEquals(0, $this->m->main("abcdef", "abcdefy", 0));
// Complex match.
$this->m->setThreshold(0.7);
$this->assertEquals(4, $this->m->main("I am the very model of a modern major general.", " that berry ", 5));
$this->m->setThreshold(0.5);
// Test null inputs.
try {
$this->m->main(null, null, 0);
$this->fail();
} catch (\InvalidArgumentException $e) {
}
}