From 5a7333f44e4e9fec42fd489879b0354b759d0337 Mon Sep 17 00:00:00 2001 From: Mischa ter Smitten Date: Wed, 10 Jun 2015 14:02:43 +0200 Subject: [PATCH] Added some more tests --- src/DamerauLevenshtein.php | 2 ++ tests/DamerauLevenshteinTest.php | 53 ++++++++++++++++++++++++++++---- 2 files changed, 49 insertions(+), 6 deletions(-) diff --git a/src/DamerauLevenshtein.php b/src/DamerauLevenshtein.php index 0c6c22d..22758e1 100644 --- a/src/DamerauLevenshtein.php +++ b/src/DamerauLevenshtein.php @@ -259,6 +259,8 @@ protected function compare($firstCharacter, $secondCharacter) */ public function displayMatrix() { + $this->setupMatrix(); + $oneSize = mb_strlen($this->compOne, 'UTF-8'); $twoSize = mb_strlen($this->compTwo, 'UTF-8'); diff --git a/tests/DamerauLevenshteinTest.php b/tests/DamerauLevenshteinTest.php index 024e421..133854d 100644 --- a/tests/DamerauLevenshteinTest.php +++ b/tests/DamerauLevenshteinTest.php @@ -7,7 +7,7 @@ class DamerauLevenshteinTest extends \PHPUnit_Framework_TestCase { /** - * Test for `getSimilarity`. + * Tests `getSimilarity`. * * @return void */ @@ -62,7 +62,7 @@ public function testGetSimilarity() } /** - * Test for `getInsCost`. + * Tests `getInsCost`. * * @return void */ @@ -98,7 +98,7 @@ public function testGetInsCost() } /** - * Test for `getDelCost`. + * Tests `getDelCost`. * * @return void */ @@ -134,7 +134,7 @@ public function testGetDelCost() } /** - * Test for `getSubCost`. + * Tests `getSubCost`. * * @return void */ @@ -170,7 +170,7 @@ public function testGetSubCost() } /** - * Test for `getTransCost`. + * Tests `getTransCost`. * * @return void */ @@ -206,7 +206,7 @@ public function testGetTransCost() } /** - * Test for `getRelativeDistance`. + * Tests `getRelativeDistance`. * * @return void */ @@ -255,6 +255,47 @@ public function testGetRelativeDistance() $this->assertEquals($expected, $result, '', $delta); } + /** + * Tests `getMatrix`. + * + * @return void + */ + public function testGetMatrix() + { + list($firstString, $secondString) = $this->getDefaultStrings(); + + $DamerauLevenshtein = new DamerauLevenshtein($firstString, $secondString); + $actual = $DamerauLevenshtein->getMatrix(); + $expected = array( + array(0, 1, 2, 3), + array(1, 1, 2, 3), + array(2, 2, 2, 3), + array(3, 3, 3, 3) + ); + $this->assertSame($expected, $actual); + } + + /** + * Tests `displayMatrix`. + * + * @return void + */ + public function testDisplayMatrix() + { + list($firstString, $secondString) = $this->getDefaultStrings(); + + $DamerauLevenshtein = new DamerauLevenshtein($firstString, $secondString); + $actual = $DamerauLevenshtein->displayMatrix(); + $expected = implode('', array( + " foo\n", + " 0123\n", + "b1123\n", + "a2223\n", + "r3333\n", + )); + $this->assertSame($expected, $actual); + } + /** * Returns the default costs. *