PHP Classes

File: tests/FuzzySearch/SetNewListTest.php

Recommend this page to a friend!
  Classes of AccountKiller   Fuse   tests/FuzzySearch/SetNewListTest.php   Download  
File: tests/FuzzySearch/SetNewListTest.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Fuse
Fuzzy search of arrays using the Bitap algorithm
Author: By
Last change:
Date: 15 days ago
Size: 466 bytes
 

Contents

Class file image Download
<?php

declare(strict_types=1);

use
Fuse\Fuse;

beforeEach(function () {
   
$this->fuse = new Fuse([]);
   
$this->fuse->setCollection(['Onion', 'Lettuce', 'Broccoli']);
});

test('when searching for the term Lettuce', function () {
   
$result = $this->fuse->search('Lettuce');

   
// we get a list of exactly 1 item
   
expect($result)->toHaveCount(1);

   
// whose value is the index 0, representing ["Apple"]
   
expect($result[0]['refIndex'])->toBe(1);
});