-
Notifications
You must be signed in to change notification settings - Fork 30
/
ScoringTest.php
48 lines (36 loc) · 1.42 KB
/
ScoringTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
declare(strict_types=1);
namespace Fuse\Test;
use PHPUnit\Framework\TestCase;
use Fuse\Fuse;
class ScoringTest extends TestCase
{
private static array $defaultList = ['Stove', 'My good friend Steve from college'];
private static array $defaultOptions = [];
private static function setupFuse($itemList = null, $overwriteOptions = [])
{
$list = $itemList ?? static::$defaultList;
$options = array_merge(static::$defaultOptions, $overwriteOptions);
return new Fuse($list, $options);
}
public function testIgnoreFieldNormOff()
{
$fuse = $this::setupFuse();
$result = $fuse->search('Steve');
// we get a list of containing 2 items
$this->assertCount(2, $result);
// whose values represent the indices of ["Stove", "My good friend Steve from college"]
$this->assertSame(0, $result[0]['refIndex']);
$this->assertSame(1, $result[1]['refIndex']);
}
public function testIgnoreFieldNormOffAndFieldNormWeightDecreased()
{
$fuse = $this::setupFuse(null, ['fieldNormWeight' => 0.15]);
$result = $fuse->search('Steve');
// we get a list of containing 2 items
$this->assertCount(2, $result);
// whose values represent the indices of ["My good friend Steve from college", "Stove"]
$this->assertSame(1, $result[0]['refIndex']);
$this->assertSame(0, $result[1]['refIndex']);
}
}