add tests/Strings, change String to Strings, code style updates

This commit is contained in:
Brandon Johnson
2022-07-24 00:55:07 -06:00
parent 53d235dcf3
commit 2676bb112e
16 changed files with 297 additions and 256 deletions

View File

@ -1,10 +1,10 @@
# List of all files # List of all files
## Ciphers ## Ciphers
* [Caesarcipher](./ciphers/caesarCipher.php) * [Caesarcipher](./Ciphers/CaesarCipher.php)
* [Monoalphabeticcipher](./ciphers/monoAlphabeticCipher.php) * [Monoalphabeticcipher](./Ciphers/monoAlphabeticCipher.php)
* [Morsecode](./ciphers/morseCode.php) * [Morsecode](./Ciphers/MorseCode.php)
* [Xorcipher](./ciphers/XORCipher.php) * [Xorcipher](./Ciphers/XORCipher.php)
## Conversions ## Conversions
* [Binarytodecimal](./Conversions/BinaryToDecimal.php) * [Binarytodecimal](./Conversions/BinaryToDecimal.php)
@ -21,58 +21,64 @@
* [Fibonacci](./Maths/Fibonacci.php) * [Fibonacci](./Maths/Fibonacci.php)
* [Fibonacci2](./Maths/Fibonacci2.php) * [Fibonacci2](./Maths/Fibonacci2.php)
* [Perfectsquare](./Maths/PerfectSquare.php) * [Perfectsquare](./Maths/PerfectSquare.php)
* Projecteuler
## Projecteuler * [Problem1](./Maths/ProjectEuler/Problem1.php)
* [Problem1](./ProjectEuler/Problem1.php) * [Problem2](./Maths/ProjectEuler/Problem2.php)
* [Problem2](./ProjectEuler/Problem2.php) * [Problem3](./Maths/ProjectEuler/Problem3.php)
* [Problem3](./ProjectEuler/Problem3.php) * [Problem5](./Maths/ProjectEuler/Problem5.php)
* [Problem5](./ProjectEuler/Problem5.php) * [Problem6](./Maths/ProjectEuler/Problem6.php)
* [Problem6](./ProjectEuler/Problem6.php) * [Problem7](./Maths/ProjectEuler/Problem7.php)
* [Problem7](./ProjectEuler/Problem7.php) * [Problem9](./Maths/ProjectEuler/Problem9.php)
* [Problem9](./ProjectEuler/Problem9.php)
## Searches ## Searches
* [Binary Search](./searches/binary_search.php) * [Binarysearch](./searches/BinarySearch.php)
* [Fibonaccisearch](./searches/fibonacciSearch.php) * [Fibonaccisearch](./searches/fibonacciSearch.php)
* [Linear Search](./searches/linear_search.php) * [Linearsearch](./searches/LinearSearch.php)
* [Lower Bound](./searches/lower_bound.php) * [Lowerbound](./searches/LowerBound.php)
* [Upper Bound](./searches/upper_bound.php) * [Upperbound](./searches/UpperBound.php)
## Sorting ## Sorting
* [Arraykeyssort](./sorting/arrayKeysSort.php) * [Arraykeyssort](./sorting/arrayKeysSort.php)
* [Bubblesort](./sorting/bubbleSort.php) * [Bubblesort](./Sorting/BubbleSort.php)
* [Bubblesort2](./sorting/bubbleSort2.php) * [Bubblesort2](./Sorting/BubbleSort2.php)
* [Countsort](./sorting/countSort.php) * [Countsort](./Sorting/CountSort.php)
* [Insertionsort](./sorting/insertionSort.php) * [Insertionsort](./Sorting/InsertionSort.php)
* [Mergesort](./sorting/mergeSort.php) * [Mergesort](./Sorting/MergeSort.php)
* [Quicksort](./sorting/quickSort.php) * [Quicksort](./Sorting/QuickSort.php)
* [Radixsort](./sorting/radixSort.php) * [Radixsort](./Sorting/RadixSort.php)
* [Selectionsort](./sorting/selectionSort.php) * [Selectionsort](./Sorting/SelectionSort.php)
## String ## Strings
* [Checkanagram](./String/CheckAnagram.php) * [Checkanagram](./Strings/CheckAnagram.php)
* [Checkpalindrome](./String/CheckPalindrome.php) * [Checkpalindrome](./Strings/CheckPalindrome.php)
* [Checkpalindromestring](./String/CheckPalindromeString.php) * [Checkpalindrome2](./Strings/CheckPalindrome2.php)
* [Countsentences](./String/CountSentences.php) * [Countconsonants](./Strings/CountConsonants.php)
* [Countvowels](./String/CountVowels.php) * [Countsentences](./Strings/CountSentences.php)
* [Countvowelsconsonantnumber](./String/CountVowelsConsonantNumber.php) * [Countvowels](./Strings/CountVowels.php)
* [Editdistance](./String/EditDistance.php) * [Distance](./Strings/Distance.php)
* [Maxcharacter](./String/MaxCharacter.php) * [Maxcharacter](./Strings/MaxCharacter.php)
* [Reversestring](./String/ReverseString.php) * [Reversestring](./Strings/ReverseString.php)
* [Reversewords](./String/ReverseWords.php) * [Reversewords](./Strings/ReverseWords.php)
## Tests ## Tests
* [Cipherstest](./tests/CiphersTest.php) * Ciphers
* [Ciphertest](./tests/CipherTest.php) * [Cipherstest](./tests/Ciphers/CiphersTest.php)
* [Conversionstest](./tests/ConversionsTest.php) * [Monoalphabeticciphertest](./tests/Ciphers/MonoAlphabeticCipherTest.php)
* [Decimaltobinarytest](./tests/DecimalToBinaryTest.php) * [Morsecodetest](./tests/Ciphers/MorseCodeTest.php)
* [Fibonaccisearchtest](./tests/fibonacciSearchTest.php) * Conversions
* [Mathtest](./tests/MathTest.php) * [Conversionstest](./tests/Conversions/ConversionsTest.php)
* [Monoalphabeticciphertest](./tests/MonoAlphabeticCipherTest.php) * Maths
* [Morsecodetest](./tests/MorseCodeTest.php) * [Mathstest](./tests/Maths/MathsTest.php)
* [Projecteulertest](./tests/ProjectEulerTest.php) * [Projecteulertest](./tests/Maths/ProjectEulerTest.php)
* Searches
* [Binarysearchtest](./tests/Searches/BinarySearchTest.php)
* [Searchestest](./tests/Searches/SearchesTest.php)
* Sorting * Sorting
* [Arraykeyssorttest](./tests/sorting/arrayKeysSortTest.php) * [Arraykeyssorttest](./tests/sorting/arrayKeysSortTest.php)
* [Countsorttest](./tests/sorting/countSortTest.php) * [Sortingtests](./tests/Sorting/SortingTests.php)
* [Quicksorttest](./tests/sorting/quickSortTest.php) * Strings
* [Stringtest](./tests/StringTest.php) * [Stringstest](./tests/Strings/StringsTest.php)
## Utils
* [Arrayhelpers](./Utils/ArrayHelpers.php)
* [Executiontime](./Utils/ExecutionTime.php)

View File

@ -1,23 +0,0 @@
<?php
/**
* This is a simple way to count sentence
* using php preg_match_all() function
* @param string $sentence
*/
function countSentences(string $sentence): int
{
$sentence = trim($sentence);
return preg_match_all('/[^\s|^\...](\.|\!|\?)(?!\w)/', $sentence);
}
// example
echo countSentences("Hi! Hello world."); // returns 2
echo PHP_EOL;
echo countSentences("i am testing. test...."); // returns 2
echo PHP_EOL;
echo countSentences("How are you?"); // returns 1
echo PHP_EOL;

View File

@ -1,49 +0,0 @@
<?php
/**
* This a simple function returns
* the Total number of vowels total
* number of consonant and total
* numeric number present in the
* given string using a simple
* method of looping through all
* characters present in the string
*
* @param string $string
*
*/
function countVowelsConsonant(string $string): String
{
if (empty($string)) {
throw new \Exception('Please pass a non-empty string value');
}
$vowels = ['a', 'e', 'i', 'o', 'u']; // Vowels Set
$string = strtolower($string); // For case-insensitive checking
$vowelCount = 0;
$consonantCount = 0;
$numberCount = 0;
for ($i = 0; $i < strlen($string); $i++) {
if (in_array($string[$i], $vowels)) {
$vowelCount++;
} elseif ($string[$i] >= 'a' && $string[$i] <= 'z') {
$consonantCount++;
} elseif ($string[$i] >= 0 && $string[$i] <= 9 && is_numeric($string[$i])) {
$numberCount++;
}
}
return 'total vowels - ' . $vowelCount . PHP_EOL .
'total consonant - ' . $consonantCount . PHP_EOL .
'total numeric number -' . $numberCount . PHP_EOL;
}
// example
echo countVowelsConsonant('Hello World. 12345');
echo countVowelsConsonant('Count Vowels, Consonant and numeric number. 09876');

View File

@ -1,12 +0,0 @@
<?php
function reverse_words(string $text)
{
$text = trim($text);
$words = explode(' ', $text);
$reversedWords = [];
for ($i = (count($words) - 1); $i >= 0; $i--) {
$reversedWords[] = $words[$i];
}
return implode(' ', $reversedWords);
}

View File

@ -1,5 +1,13 @@
<?php <?php
/**
* Checks if two strings are anagrams of each other.
*
* @param string $originalString
* @param string $testString
* @param bool $caseInsensitive
* @return bool
*/
function isAnagram(string $originalString, string $testString, bool $caseInsensitive = true) function isAnagram(string $originalString, string $testString, bool $caseInsensitive = true)
{ {
if ($caseInsensitive) if ($caseInsensitive)
@ -8,8 +16,8 @@ function isAnagram(string $originalString, string $testString, bool $caseInsensi
$testString = strtolower($testString); $testString = strtolower($testString);
} }
//count_chars(string, mode = 1) returns key-value pairs with character as key, frequency as value // count_chars(string, mode = 1) returns key-value pairs with character as key, frequency as value
//We can directly compare the arrays in this case // We can directly compare the arrays in this case
if (count_chars($originalString, 1) == count_chars($testString, 1)) if (count_chars($originalString, 1) == count_chars($testString, 1))
{ {
return true; return true;

View File

@ -1,21 +1,32 @@
<?php <?php
function is_palindrome(string $string, bool $caseInsensitive = true) /**
* Checks if a string is a palindrome
*
* @param string $string
* @param bool $caseInsensitive
* @return bool
*/
function isPalindrome(string $string, bool $caseInsensitive = true)
{ {
$string = trim($string); // Removing leading and trailing spaces $string = trim($string); // Removing leading and trailing spaces
if (empty($string)) { if (empty($string))
{
return false; // Returning false for an Empty String return false; // Returning false for an Empty String
} }
if ($caseInsensitive) { if ($caseInsensitive)
{
$string = strtolower($string); // Converting string to lowercase for case-insensitive check $string = strtolower($string); // Converting string to lowercase for case-insensitive check
} }
$characters = str_split($string); $characters = str_split($string);
for ($i = 0; $i < count($characters); $i++) { for ($i = 0; $i < count($characters); $i++)
if ($characters[$i] !== $characters[count($characters) - ($i + 1)]) { {
if ($characters[$i] !== $characters[count($characters) - ($i + 1)])
{
return false; return false;
} }
} }

View File

@ -4,9 +4,7 @@
* This is a simple way to check palindrome string * This is a simple way to check palindrome string
* using php strrev() function * using php strrev() function
* make it simple * make it simple
*/ *
/**
* @param string $string * @param string $string
* @param bool $caseInsensitive * @param bool $caseInsensitive
*/ */
@ -15,7 +13,8 @@ function checkPalindromeString(string $string, bool $caseInsensitive = true): St
//removing spaces //removing spaces
$string = trim($string); $string = trim($string);
if (empty($string)) { if (empty($string))
{
throw new \Exception('You are given empty string. Please give a non-empty string value'); throw new \Exception('You are given empty string. Please give a non-empty string value');
} }
@ -23,11 +22,13 @@ function checkPalindromeString(string $string, bool $caseInsensitive = true): St
* for case-insensitive * for case-insensitive
* lowercase string conversion * lowercase string conversion
*/ */
if ($caseInsensitive) { if ($caseInsensitive)
{
$string = strtolower($string); $string = strtolower($string);
} }
if ($string !== strrev($string)) { if ($string !== strrev($string))
{
return $string . " - not a palindrome string." . PHP_EOL; return $string . " - not a palindrome string." . PHP_EOL;
} }

View File

@ -0,0 +1,31 @@
<?php
/**
* Function returns the total number of consonants present in the given
* string using a linear search through the string
*
* @param string $string
* @return int
*/
function countConsonants(string $string): Int
{
if (empty($string)) {
throw new \Exception('Please pass a non-empty string value');
}
$vowels = ['a', 'e', 'i', 'o', 'u']; // Vowels Set
$string = strtolower($string); // For case-insensitive checking
$consonantCount = 0;
for ($i = 0; $i < strlen($string); $i++)
{
if (!in_array($string[$i], $vowels) &&
$string[$i] >= 'a' && $string[$i] <= 'z')
{
$consonantCount++;
}
}
return $consonantCount;
}

View File

@ -0,0 +1,15 @@
<?php
/**
* This is a simple way to count sentence
* using php preg_match_all() function
*
* @param string $sentence
* @return int
*/
function countSentences(string $sentence): int
{
$sentence = trim($sentence);
return preg_match_all('/[^\s|^\...](\.|\!|\?)(?!\w)/', $sentence);
}

View File

@ -1,50 +1,46 @@
<?php <?php
/** /**
* This function returns * This function returns the total number of vowels present in
* the Total no. of vowels * the given string using a simple method of looping through
* present in the given * all the characters present in the string.
* string using a simple
* method of looping
* through all the
* characters present in
* the string.
* *
* @param string $string * @param string $string
* @return int $noOfVowels * @return int $numberOfVowels
*/ */
function countVowelsSimple(string $string) function countVowelsSimple(string $string)
{ {
if (empty($string)) { if (empty($string))
{
throw new \Exception('Please pass a non-empty string value'); throw new \Exception('Please pass a non-empty string value');
} }
$noOfVowels = 0; $numberOfVowels = 0;
$vowels = ['a', 'e', 'i', 'o', 'u']; // Vowels Set $vowels = ['a', 'e', 'i', 'o', 'u']; // Vowels Set
$string = strtolower($string); // For case-insensitive checking $string = strtolower($string); // For case-insensitive checking
$characters = str_split($string); // Splitting the string to a Character Array. $characters = str_split($string); // Splitting the string to a Character Array.
foreach ($characters as $character) { foreach ($characters as $character)
if (in_array($character, $vowels)) { {
$noOfVowels++; if (in_array($character, $vowels))
{
$numberOfVowels++;
} }
} }
return $noOfVowels; return $numberOfVowels;
} }
/** /**
* This function returns * This function returns the Total number of vowels present in the given
* the Total no. of vowels * string using a regular expression.
* present in the given
* string using a
* regular expression.
* *
* @param string $string * @param string $string
* @return int * @return int
*/ */
function countVowelsRegex(string $string) function countVowelsRegex(string $string)
{ {
if (empty($string)) { if (empty($string))
{
throw new \Exception('Please pass a non-empty string value'); throw new \Exception('Please pass a non-empty string value');
} }
$string = strtolower($string); // For case-insensitive checking $string = strtolower($string); // For case-insensitive checking

View File

@ -1,13 +1,15 @@
<?php <?php
/** /**
* Edit distance (Levenshtein distance). * Find distance (Levenshtein distance)
*
* Compute the difference between two sequences, ie, the minimum number of changes * Compute the difference between two sequences, ie, the minimum number of changes
* to get to $str2 from $str1 * to get to $str2 from $str1
*
* @param string $str1 * @param string $str1
* @param string $str2 * @param string $str2
* @return int the minimum number of changes to transform one string into another * @return int the minimum number of changes to transform one string into another
*/ */
function editDistance($str1, $str2) function findDistance($str1, $str2)
{ {
$lenStr1 = strlen($str1); $lenStr1 = strlen($str1);
$lenStr2 = strlen($str2); $lenStr2 = strlen($str2);
@ -22,6 +24,7 @@ function editDistance($str1, $str2)
$distanceVectorInit = []; $distanceVectorInit = [];
$distanceVectorFinal = []; $distanceVectorFinal = [];
for ($i = 0; $i < $lenStr1 + 1; $i++) { for ($i = 0; $i < $lenStr1 + 1; $i++) {
$distanceVectorInit[] = 0; $distanceVectorInit[] = 0;
$distanceVectorFinal[] = 0; $distanceVectorFinal[] = 0;
@ -33,9 +36,11 @@ function editDistance($str1, $str2)
for ($i = 0; $i < $lenStr2; $i++) { for ($i = 0; $i < $lenStr2; $i++) {
$distanceVectorFinal[0] = $i + 1; $distanceVectorFinal[0] = $i + 1;
// use formula to fill in the rest of the row // use formula to fill in the rest of the row
for ($j = 0; $j < $lenStr1; $j++) { for ($j = 0; $j < $lenStr1; $j++) {
$substitutionCost = 0; $substitutionCost = 0;
if ($str1[$j] == $str2[$i]) { if ($str1[$j] == $str2[$i]) {
$substitutionCost = $distanceVectorInit[$j]; $substitutionCost = $distanceVectorInit[$j];
} else { } else {

View File

@ -1,8 +1,6 @@
<?php <?php
/** /**
* This function returns * This function returns the character which is repeated maximum number of
* the character which is
* repeated maximum no. of
* times in the given string. * times in the given string.
* *
* @param string $string * @param string $string
@ -20,9 +18,11 @@ function maxCharacter(string $string)
foreach ($characters as $character) { foreach ($characters as $character) {
$currentCharacterCount = 1; $currentCharacterCount = 1;
if (isset($characterCountTable[$character])) { if (isset($characterCountTable[$character])) {
$currentCharacterCount = $characterCountTable[$character] + 1; $currentCharacterCount = $characterCountTable[$character] + 1;
} }
$characterCountTable[$character] = $currentCharacterCount; $characterCountTable[$character] = $currentCharacterCount;
} }

View File

@ -1,6 +1,12 @@
<?php <?php
function reverse_string(string $string) /**
* This function returns a given string in reverse order
*
* @param string $string
* @return string
*/
function reverseString(string $string)
{ {
$string = trim($string); // Removing leading and trailing spaces $string = trim($string); // Removing leading and trailing spaces

22
Strings/ReverseWords.php Normal file
View File

@ -0,0 +1,22 @@
<?php
/**
* This function returns a given sentence with its words
* in reverse order
*
* @param string $string
* @return string
*/
function reverseWords(string $text)
{
$text = trim($text);
$words = explode(' ', $text);
$reversedWords = [];
for ($i = (count($words) - 1); $i >= 0; $i--)
{
$reversedWords[] = $words[$i];
}
return implode(' ', $reversedWords);
}

View File

@ -1,78 +0,0 @@
<?php
use function PHPUnit\Framework\assertEquals;
use function PHPUnit\Framework\assertFalse;
use function PHPUnit\Framework\assertNotEquals;
use function PHPUnit\Framework\assertTrue;
use PHPUnit\Framework\TestCase;
require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/../String/CheckPalindrome.php';
require_once __DIR__ . '/../String/ReverseString.php';
require_once __DIR__ . '/../String/ReverseWords.php';
require_once __DIR__ . '/../String/CheckAnagram.php';
require_once __DIR__ . '/../String/MaxCharacter.php';
require_once __DIR__ . '/../String/CountVowels.php';
require_once __DIR__ . '/../String/EditDistance.php';
class StringTest extends TestCase
{
public function testIsPalindrome()
{
assertTrue(is_palindrome('MaDam')); // true
assertFalse(is_palindrome('ThisIsTest')); // false
assertFalse(is_palindrome('')); // false
assertTrue(is_palindrome('Sator Arepo Tenet Opera Rotas')); // true
assertFalse(is_palindrome('Sator Arepo Tenet Opera Rotas', false)); // false since we are doing case-sensitive check
}
public function testReverseString()
{
assertEquals('txet emos si sihT', reverse_string('This is some text'));
assertEquals('mADaM', reverse_string('MaDAm'));
assertNotEquals('MaDAm', reverse_string('MaDAm'));
}
public function testReverseWords()
{
assertEquals('Fun is Coding PHP', reverse_words('PHP Coding is Fun'));
assertEquals('OneWord', reverse_words('OneWord'));
assertEquals('Text different some is This', reverse_words('This is some different Text'));
}
public function testIsAnagram()
{
assertTrue(isAnagram("php", "PHP")); // By default it's case-insensitive
assertFalse(isAnagram("php", "PHP", false)); // Make case-sensitive check
assertTrue(isAnagram("php is fun", "pin hpf us"));
assertFalse(isAnagram("Hello", " Hello")); //Extra space character
assertTrue(isAnagram("ScRamble", "SRlmcaeb", false)); // Check with a mixture of upper and lower case
}
public function testMaxCharacter()
{
assertEquals(maxCharacter("this is test for max character repetition"), 't');
assertEquals(maxCharacter("This is Test for max characTer repetition"), 't');
assertEquals(maxCharacter(" "), ' ');
}
public function testCountVowels()
{
assertEquals(countVowelsSimple("This is a string with 7 vowels"), 7);
assertEquals(countVowelsSimple("hello world"), 3);
assertEquals(countVowelsRegex("Just A list of somE aaaaaaaaaa"), 16);
assertEquals(countVowelsRegex("This is a string with 7 vowels"), 7);
assertEquals(countVowelsRegex("hello world"), 3);
assertEquals(countVowelsRegex("Just A list of somE aaaaaaaaaa"), 16);
}
public function testEditDistance()
{
assertEquals(editDistance("hello", "hallo"), 1);
assertEquals(editDistance("hallo", "hello"), 1);
assertEquals(editDistance("sunday", "sunday"), 0);
assertEquals(editDistance("saturday", "sunday"), 3);
}
}

View File

@ -0,0 +1,102 @@
<?php
use function PHPUnit\Framework\assertEquals;
use function PHPUnit\Framework\assertFalse;
use function PHPUnit\Framework\assertNotEquals;
use function PHPUnit\Framework\assertTrue;
use PHPUnit\Framework\TestCase;
require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/../String/CheckPalindrome.php';
require_once __DIR__ . '/../String/ReverseString.php';
require_once __DIR__ . '/../String/ReverseWords.php';
require_once __DIR__ . '/../String/CheckAnagram.php';
require_once __DIR__ . '/../String/MaxCharacter.php';
require_once __DIR__ . '/../String/CountVowels.php';
require_once __DIR__ . '/../String/CountConsonants.php';
require_once __DIR__ . '/../String/Distance.php';
class StringTest extends TestCase
{
public function testIsPalindrome()
{
assertTrue(isPalindrome('MaDam')); // true
assertFalse(isPalindrome('ThisIsTest')); // false
assertFalse(isPalindrome('')); // false
assertTrue(isPalindrome('Sator Arepo Tenet Opera Rotas')); // true
assertFalse(isPalindrome('Sator Arepo Tenet Opera Rotas', false)); // false since we are doing case-sensitive check
}
public function testIsPalindrome2()
{
assertTrue(checkPalindromeString('131')); // true
assertFalse(checkPalindromeString('roman')); // false
assertTrue(checkPalindromeString('Level', true)); // true
assertFalse(checkPalindromeString('Level', false)); // false
assertFalse(checkPalindromeString('palindrome')); // false
}
public function testCountSentences()
{
assertEquals(countSentences('Hi! Hello world.'), 2);
assertEquals(countSentences('i am testing. test....'), 2);
assertEquals(countSentences('How are you?'), 1);
}
public function testReverseString()
{
assertEquals('txet emos si sihT', reverseString('This is some text'));
assertEquals('mADaM', reverseString('MaDAm'));
assertNotEquals('MaDAm', reverseString('MaDAm'));
}
public function testReverseWords()
{
assertEquals('Fun is Coding PHP', reverseWords('PHP Coding is Fun'));
assertEquals('OneWord', reverseWords('OneWord'));
assertEquals('Text different some is This', reverseWords('This is some different Text'));
}
public function testIsAnagram()
{
assertTrue(isAnagram("php", "PHP")); // By default it's case-insensitive
assertFalse(isAnagram("php", "PHP", false)); // Make case-sensitive check
assertTrue(isAnagram("php is fun", "pin hpf us"));
assertFalse(isAnagram("Hello", " Hello")); //Extra space character
assertTrue(isAnagram("ScRamble", "SRlmcaeb", false)); // Check with a mixture of upper and lower case
}
public function testMaxCharacter()
{
assertEquals(maxCharacter("this is test for max character repetition"), 't');
assertEquals(maxCharacter("This is Test for max characTer repetition"), 't');
assertEquals(maxCharacter(" "), ' ');
}
public function testCountVowels()
{
assertEquals(countVowelsSimple("This is a string with 7 vowels"), 7);
assertEquals(countVowelsSimple("hello world"), 3);
assertEquals(countVowelsRegex("Just A list of somE aaaaaaaaaa"), 16);
assertEquals(countVowelsRegex("This is a string with 7 vowels"), 7);
assertEquals(countVowelsRegex("hello world"), 3);
assertEquals(countVowelsRegex("Just A list of somE aaaaaaaaaa"), 16);
}
public function testCountConsonants()
{
assertEquals(countConsonants("This is a string with 19 consonants"), 19);
assertEquals(countConsonants("hello world"), 7);
assertEquals(countConsonants("Just A list of somE aaaaaaaaaa"), 9);
}
public function testFindDistance()
{
assertEquals(findDistance("hello", "hallo"), 1);
assertEquals(findDistance("hallo", "hello"), 1);
assertEquals(findDistance("sunday", "sunday"), 0);
assertEquals(findDistance("saturday", "sunday"), 3);
}
}