update fibonacciSearch.php to FibonacciSearch.php for consistency

This commit is contained in:
Brandon Johnson 2022-07-24 01:07:35 -06:00
parent 1eef2e1d93
commit 35ed4625eb
13 changed files with 80 additions and 56 deletions

View File

@ -32,17 +32,12 @@
## Searches
* [Binarysearch](./Searches/BinarySearch.php)
## Searches
* [Fibonaccisearch](./searches/fibonacciSearch.php)
## Searches
* [Fibonaccisearch](./Searches/FibonacciSearch.php)
* [Linearsearch](./Searches/LinearSearch.php)
* [Lowerbound](./Searches/LowerBound.php)
* [Upperbound](./Searches/UpperBound.php)
## Sorting
* [Arraykeyssort](./sorting/arrayKeysSort.php)
* [Bubblesort](./Sorting/BubbleSort.php)
* [Bubblesort2](./Sorting/BubbleSort2.php)
* [Countsort](./Sorting/CountSort.php)
@ -75,10 +70,10 @@
* [Mathstest](./tests/Maths/MathsTest.php)
* [Projecteulertest](./tests/Maths/ProjectEulerTest.php)
* Searches
* [Binarysearchtest](./tests/Searches/BinarySearchTest.php)
* [Searchestest](./tests/Searches/SearchesTest.php)
* Sorting
* [Arraykeyssorttest](./tests/sorting/arrayKeysSortTest.php)
* Sorting
* [Sortingtests](./tests/Sorting/SortingTests.php)
* Strings
* [Stringstest](./tests/Strings/StringsTest.php)

View File

@ -61,6 +61,14 @@ function binarySearchIterative($list, $target)
*/
function binarySearchByRecursion($list, $target, $start, $end)
{
if (count($list) == 0) {
return null;
}
if (count($list) < 2) {
return $list[0] == $target ? 0 : null;
}
if ($start > $end)
return null;

View File

@ -1,6 +1,7 @@
<?php
require_once __DIR__ . '/../../Utils/ArrayHelpers.php';
require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/../Utils/ArrayHelpers.php';
/**
* Lower Bound of an element is minimum index that an element would be placed

View File

@ -1,6 +1,7 @@
<?php
require_once __DIR__ . '/../../Utils/ArrayHelpers.php';
require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/../Utils/ArrayHelpers.php';
/**
* Upper Bound of an element is maximum index that an element would be placed

View File

@ -34,9 +34,3 @@ function checkPalindromeString(string $string, bool $caseInsensitive = true): St
return $string . " - a palindrome string." . PHP_EOL;
}
// example
echo checkPalindromeString('131');
echo checkPalindromeString('roman');
echo checkPalindromeString('Level');
echo checkPalindromeString('palindrome');

View File

@ -11,10 +11,10 @@ class CiphersTest extends TestCase
{
public function testCaesarCipher()
{
assertEquals('Aopz pz h alza.', encrypt('This is a test.', 7));
assertEquals('Aopz pz h alza.', encrypt('This is a test.', 7 + 26));
assertEquals('This is a test.', decrypt('Aopz pz h alza.', 7));
assertEquals('This is a test.', decrypt('Aopz pz h alza.', 7 + 26));
$this->assertEquals('Aopz pz h alza.', encrypt('This is a test.', 7));
$this->assertEquals('Aopz pz h alza.', encrypt('This is a test.', 7 + 26));
$this->assertEquals('This is a test.', decrypt('Aopz pz h alza.', 7));
$this->assertEquals('This is a test.', decrypt('Aopz pz h alza.', 7 + 26));
}
public function testXorCipher()
@ -22,7 +22,7 @@ class CiphersTest extends TestCase
$input_str = "test@string";
$key = "test-key";
$invalid_key = "wrong-key";
assertEquals( $input_str, xorCipher( xorCipher( $input_str , $key) , $key));
assertNotEquals( $input_str, xorCipher( xorCipher( $input_str , $key) , $invalid_key));
$this->assertEquals( $input_str, xorCipher( xorCipher( $input_str , $key) , $key));
$this->assertNotEquals( $input_str, xorCipher( xorCipher( $input_str , $key) , $invalid_key));
}
}

View File

@ -6,6 +6,7 @@ use PHPUnit\Framework\TestCase;
require_once __DIR__ . '/../../vendor/autoload.php';
require_once __DIR__ . '/../../Conversions/BinaryToDecimal.php';
require_once __DIR__ . '/../../Conversions/DecimalToBinary.php';
require_once __DIR__ . '/../../Conversions/OctalToDecimal.php';
require_once __DIR__ . '/../../Conversions/HexadecimalToDecimal.php';

View File

@ -54,10 +54,10 @@ class MathTest extends TestCase
public function testPerfectSquare()
{
assertTrue(is_perfect_square(25));
assertFalse(is_perfect_square(43));
assertFalse(is_perfect_square(2));
assertTrue(is_perfect_square(225));
assertTrue(isPerfectSquare(25));
assertFalse(isPerfectSquare(43));
assertFalse(isPerfectSquare(2));
assertTrue(isPerfectSquare(225));
}
public function testFastExponentiation()
@ -80,10 +80,10 @@ class MathTest extends TestCase
public function testFibonacciGenerator()
{
assertEquals([0, 1, 1, 2, 3], loop(5, fib()));
assertEquals([0, 1, 1, 2, 3, 5, 8, 13, 21, 34], loop(10, fib()));
assertEquals([0, 1, 1, 2, 3], iterator_to_array(loop(5, fib())));
assertEquals([0, 1, 1, 2, 3, 5, 8, 13, 21, 34], iterator_to_array(loop(10, fib())));
assertEquals([0, 1, 1, 2, 3], loop(5, loop()));
assertEquals([0, 1, 1, 2, 3, 5, 8, 13, 21, 34], loop(10, fib()));
assertEquals([0, 1, 1, 2, 3], iterator_to_array(loop(5, fib())));
assertEquals([0, 1, 1, 2, 3, 5, 8, 13, 21, 34], iterator_to_array(loop(10, fib())));
}
}

View File

@ -9,6 +9,8 @@ require_once __DIR__ . '/../../vendor/autoload.php';
require_once __DIR__ . '/../../Searches/BinarySearch.php';
require_once __DIR__ . '/../../Searches/FibonacciSearch.php';
require_once __DIR__ . '/../../Searches/LinearSearch.php';
require_once __DIR__ . '/../../Searches/LowerBound.php';
require_once __DIR__ . '/../../Searches/UpperBound.php';
class SearchesTest extends TestCase
{
@ -58,10 +60,10 @@ class SearchesTest extends TestCase
{
$list = [0];
$target = 0;
$result = binarySearchByRecursion($list, $target, 0, 1);
$result = binarySearchByRecursion($list, $target, 0, 0);
assertEquals(0, $result);
$target = 1;
$result = binarySearchByRecursion($list, $target, 0, 1);
$result = binarySearchByRecursion($list, $target, 0, 0);
assertEquals(null, $result);
}
@ -69,13 +71,13 @@ class SearchesTest extends TestCase
{
$list = [0, 1];
$target = 0;
$result = binarySearchByRecursion($list, $target, 0, 2);
$result = binarySearchByRecursion($list, $target, 0, 1);
assertEquals(0, $result);
$target = 1;
$result = binarySearchByRecursion($list, $target, 0, 2);
$result = binarySearchByRecursion($list, $target, 0, 1);
assertEquals(1, $result);
$target = 2;
$result = binarySearchByRecursion($list, $target, 0, 2);
$result = binarySearchByRecursion($list, $target, 0, 1);
assertEquals(null, $result);
}
@ -83,16 +85,16 @@ class SearchesTest extends TestCase
{
$list = [0, 1, 2];
$target = 0;
$result = binarySearchByRecursion($list, $target, 0, 3);
$result = binarySearchByRecursion($list, $target, 0, 2);
assertEquals(0, $result);
$target = 1;
$result = binarySearchByRecursion($list, $target, 0, 3);
$result = binarySearchByRecursion($list, $target, 0, 2);
assertEquals(1, $result);
$target = 2;
$result = binarySearchByRecursion($list, $target, 0, 3);
$result = binarySearchByRecursion($list, $target, 0, 2);
assertEquals(2, $result);
$target = 3;
$result = binarySearchByRecursion($list, $target, 0, 3);
$result = binarySearchByRecursion($list, $target, 0, 2);
assertEquals(null, $result);
}

View File

@ -143,4 +143,33 @@ class SortingTests extends TestCase
$end = microtime(true);
$this->assertLessThan(1, $end - $start);
}
public function testCountSortCipher()
{
$firstArray = array(20, 16, -5, -8, 6, 12, 2, 4, -3, 9);
$expectedResultOne = array(-8, -5, -3, 2, 4, 6, 9, 12, 16, 20);
$secondArray = array(-6, 12, 14, 17, 5, 4, -9, 15, 0, -8);
$expectedResultTwo = array(-9, -8, -6, 0, 4, 5, 12, 14, 15, 17);
$resultOne = countSort($firstArray, $minRange = -10, $maxRange = 20);
$resultTwo = countSort($secondArray, $minRange = -10, $maxRange = 20);
$this->assertEquals($expectedResultOne, $resultOne);
$this->assertEquals($expectedResultTwo, $resultTwo);
}
public function testQuickSortCipher()
{
$array1 = [20, 16, -5, -8, 6, 12, 2, 4, -3, 9];
$array2 = [-6, 12, 14, 17, 5, 4, -9, 15, 0, -8];
$result1 = [-8, -5, -3, 2, 4, 6, 9, 12, 16, 20];
$result2 = [-9, -8, -6, 0, 4, 5, 12, 14, 15, 17];
$test1 = quickSort($array1);
$test2 = quickSort($array2);
$this->assertEquals($result1, $test1);
$this->assertEquals($result2, $test2);
}
}

View File

@ -6,16 +6,18 @@ use function PHPUnit\Framework\assertNotEquals;
use function PHPUnit\Framework\assertTrue;
use PHPUnit\Framework\TestCase;
require_once __DIR__ . '/../vendor/autoload.php';
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';
require_once __DIR__ . '/../../Strings/CheckAnagram.php';
require_once __DIR__ . '/../../Strings/CheckPalindrome.php';
require_once __DIR__ . '/../../Strings/CheckPalindrome2.php';
require_once __DIR__ . '/../../Strings/CountConsonants.php';
require_once __DIR__ . '/../../Strings/CountSentences.php';
require_once __DIR__ . '/../../Strings/CountVowels.php';
require_once __DIR__ . '/../../Strings/Distance.php';
require_once __DIR__ . '/../../Strings/MaxCharacter.php';
require_once __DIR__ . '/../../Strings/ReverseString.php';
require_once __DIR__ . '/../../Strings/ReverseWords.php';
class StringTest extends TestCase
{
@ -28,15 +30,6 @@ class StringTest extends TestCase
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);