Completed
Push — master ( a89c11...c36570 )
by raphael
04:54
created

FinderTest::testThreshold()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.8333
c 0
b 0
f 0
cc 1
nc 1
nop 0
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