Skip to content

Commit

Permalink
fuzzytest do cover many more cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Divyeshhhh committed Apr 18, 2024
1 parent c81c735 commit f5da963
Showing 1 changed file with 46 additions and 2 deletions.
48 changes: 46 additions & 2 deletions tests/FuzzyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,57 @@ class FuzzyTest extends TestCase
public function testFuzzySearch(): void
{
$strings = ['Espresso', 'Cappuccino', 'Latte', 'Americano', 'Mocha'];
$searchTerm = 'Espreso';
$threshold = 1;

// Test with normal data (correct spelling)
$searchTerm = 'Espresso';
$threshold = 1;
$result = Utility::fuzzySearch($searchTerm, $strings, $threshold);

$this->assertContains('Espresso', $result);
$this->assertNotContains('Mocha', $result);

// Test with misspelling within threshold
$searchTerm = 'Espreso'; // Missing 's'
$threshold = 1;
$result = Utility::fuzzySearch($searchTerm, $strings, $threshold);

$this->assertContains('Espresso', $result);

// Test with misspelling exceeding threshold
$searchTerm = 'Espressso'; // Extra 's'
$threshold = 1;
$result = Utility::fuzzySearch($searchTerm, $strings, $threshold);

$this->assertContains('Espresso', $result);

// Test with empty search term
$searchTerm = '';
$threshold = 1;
$result = Utility::fuzzySearch($searchTerm, $strings, $threshold);

$this->assertEquals([], $result); // Expect no matches

// Test with non-string search term (integer)
$searchTerm = (string) 123;
$threshold = 1;
$result = Utility::fuzzySearch($searchTerm, $strings, $threshold);

$this->assertEquals([], $result); // Expect no matches (type mismatch)

// Test with search term containing special characters
$searchTerm = 'Latte!';
$threshold = 1;
$result = Utility::fuzzySearch($searchTerm, $strings, $threshold);

$this->assertContains('Latte', $result); // Should still match 'Latte'

// Test with case sensitivity (optional, depending on your needs)
$searchTerm = 'eSPRESSO'; // All uppercase
$threshold = 1;
$result = Utility::fuzzySearch($searchTerm, $strings, $threshold);
// Depending on your implementation, this might match (case-insensitive)
// or not match (case-sensitive). Update assertions accordingly.

}

public function testLevenshteinDistance(): void
Expand Down

0 comments on commit f5da963

Please sign in to comment.