<?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'));
assertFalse(is_palindrome('ThisIsTest'));
assertFalse(is_palindrome(''));
assertTrue(is_palindrome('Sator Arepo Tenet Opera Rotas'));
assertFalse(is_palindrome('Sator Arepo Tenet Opera Rotas', false));
}
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"));
assertFalse(isAnagram("php", "PHP", false));
assertTrue(isAnagram("php is fun", "pin hpf us"));
assertFalse(isAnagram("Hello", " Hello"));
assertTrue(isAnagram("ScRamble", "SRlmcaeb", false));
}
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);
}
}