1
|
|
|
<?php namespace SimilarText\Test; |
2
|
|
|
|
3
|
|
|
use SimilarText\Finder; |
4
|
|
|
use PHPUnit\Framework\TestCase; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Class FinderTest |
8
|
|
|
* @package SimilarText\Test |
9
|
|
|
*/ |
10
|
|
|
class FinderTest extends TestCase |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* Test first() method |
14
|
|
|
*/ |
15
|
|
|
public function testFirst() |
16
|
|
|
{ |
17
|
|
|
$text_finder = new Finder('bananna', ['apple', 'kiwi', 'banana', 'orange', 'banner']); |
18
|
|
|
$this->assertEquals('banana', $text_finder->first()); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Test all() method |
23
|
|
|
*/ |
24
|
|
|
public function testAll() |
25
|
|
|
{ |
26
|
|
|
$text_finder = new Finder('bananna', ['apple', 'kiwi', 'Ü◘ö']); |
27
|
|
|
$this->assertCount(3, $text_finder->all()); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Test hasExactMatch() method |
32
|
|
|
*/ |
33
|
|
|
public function testHasExactMatch() { |
34
|
|
|
$text_finder = new Finder('banana', ['apple', 'kiwi', 'banana']); |
35
|
|
|
$this->assertTrue($text_finder->hasExactMatch()); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Test hasExactMatch() method |
40
|
|
|
*/ |
41
|
|
|
public function testHasNotExactMatch() { |
42
|
|
|
$text_finder = new Finder('banana', ['apple', 'kiwi']); |
43
|
|
|
$this->assertFalse($text_finder->hasExactMatch()); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Test threshold() method |
48
|
|
|
*/ |
49
|
|
|
public function testThreshold() { |
50
|
|
|
$text_finder = new Finder('bananna', ['apple', 'kiwi', 'banana', 'orange', 'bandana', 'banana', 'canary']); |
51
|
|
|
$this->assertEquals(['banana', 'bandana', 'canary'], $text_finder->threshold(4)->all()); |
52
|
|
|
|
53
|
|
|
$text_finder = new Finder('bananna', ['apple', 'kiwi', 'banana', 'orange', 'bandana', 'banana', 'canary']); |
54
|
|
|
$this->assertEquals('banana', $text_finder->threshold(2)->first()); |
55
|
|
|
|
56
|
|
|
$text_finder = new Finder('banana', ['apple', 'kiwi', 'banana', 'orange', 'bandana', 'banana', 'canary']); |
57
|
|
|
$this->assertEquals('banana', $text_finder->threshold(0)->first()); |
58
|
|
|
|
59
|
|
|
$text_finder = new Finder('bananna', ['apple', 'kiwi', 'orange', 'melon']); |
60
|
|
|
$this->assertNull($text_finder->threshold(2)->first()); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|