mirror of
https://github.com/TheAlgorithms/PHP.git
synced 2025-07-11 20:16:24 +02:00
Merge pull request #128 from anamarijapapic/fix/phpunit-sorting-tests
[PHPUnit testing]: Fix sorting tests not running.
This commit is contained in:
6
.github/workflows/ci.yml
vendored
6
.github/workflows/ci.yml
vendored
@ -14,6 +14,12 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Setup PHP
|
||||||
|
uses: shivammathur/setup-php@v2
|
||||||
|
with:
|
||||||
|
php-version: '7.4'
|
||||||
|
ini-values: xdebug.max_nesting_level=512
|
||||||
|
|
||||||
- name: Validate composer.json and composer.lock
|
- name: Validate composer.json and composer.lock
|
||||||
run: composer validate
|
run: composer validate
|
||||||
|
|
||||||
|
@ -106,7 +106,7 @@
|
|||||||
* Sorting
|
* Sorting
|
||||||
* [Arraykeyssorttest](./tests/Sorting/ArrayKeysSortTest.php)
|
* [Arraykeyssorttest](./tests/Sorting/ArrayKeysSortTest.php)
|
||||||
* [Gnomesorttest](./tests/Sorting/GnomeSortTest.php)
|
* [Gnomesorttest](./tests/Sorting/GnomeSortTest.php)
|
||||||
* [Sortingtests](./tests/Sorting/SortingTests.php)
|
* [Sortingtest](./tests/Sorting/SortingTest.php)
|
||||||
* Strings
|
* Strings
|
||||||
* [Stringstest](./tests/Strings/StringsTest.php)
|
* [Stringstest](./tests/Strings/StringsTest.php)
|
||||||
|
|
||||||
|
@ -2,13 +2,13 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $array
|
* @param $array
|
||||||
* @param $min
|
|
||||||
* @param $max
|
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
function countSort($array, $min, $max)
|
function countSort($array)
|
||||||
{
|
{
|
||||||
$count = array();
|
$count = array();
|
||||||
|
$min = min($array);
|
||||||
|
$max = max($array);
|
||||||
|
|
||||||
for ($i = $min; $i <= $max; $i++) {
|
for ($i = $min; $i <= $max; $i++) {
|
||||||
$count[$i] = 0;
|
$count[$i] = 0;
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
* @param array $array
|
* @param array $array
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
function selectionSorting(array $array)
|
function selectionSort(array $array)
|
||||||
{
|
{
|
||||||
$length = count($array);
|
$length = count($array);
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ use PHPUnit\Framework\TestCase;
|
|||||||
require_once __DIR__ . '/../../vendor/autoload.php';
|
require_once __DIR__ . '/../../vendor/autoload.php';
|
||||||
require_once __DIR__ . '/../../Ciphers/VignereCipher.php';
|
require_once __DIR__ . '/../../Ciphers/VignereCipher.php';
|
||||||
|
|
||||||
class VignereCipher extends TestCase
|
class VignereCipherTest extends TestCase
|
||||||
{
|
{
|
||||||
public function testVignereCipher()
|
public function testVignereCipher()
|
||||||
{
|
{
|
||||||
|
@ -13,7 +13,7 @@ require_once __DIR__ . '/../../Sorting/QuickSort.php';
|
|||||||
require_once __DIR__ . '/../../Sorting/RadixSort.php';
|
require_once __DIR__ . '/../../Sorting/RadixSort.php';
|
||||||
require_once __DIR__ . '/../../Sorting/SelectionSort.php';
|
require_once __DIR__ . '/../../Sorting/SelectionSort.php';
|
||||||
|
|
||||||
class SortingTests extends TestCase
|
class SortingTest extends TestCase
|
||||||
{
|
{
|
||||||
public function testBubbleSort()
|
public function testBubbleSort()
|
||||||
{
|
{
|
||||||
@ -76,9 +76,7 @@ class SortingTests extends TestCase
|
|||||||
public function testCountSort()
|
public function testCountSort()
|
||||||
{
|
{
|
||||||
$array = [-5, -10, 0, -3, 8, 5, -1, 10];
|
$array = [-5, -10, 0, -3, 8, 5, -1, 10];
|
||||||
$min = 0;
|
$sorted = countSort($array);
|
||||||
$max = 9;
|
|
||||||
$sorted = countSort($array, 0, 9);
|
|
||||||
$this->assertEquals([-10, -5, -3, -1, 0, 5, 8, 10], $sorted);
|
$this->assertEquals([-10, -5, -3, -1, 0, 5, 8, 10], $sorted);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -206,7 +204,7 @@ class SortingTests extends TestCase
|
|||||||
|
|
||||||
public function testMergeSortPerformance()
|
public function testMergeSortPerformance()
|
||||||
{
|
{
|
||||||
$array = range(1, 1000000);
|
$array = range(1, 10000);
|
||||||
$start = microtime(true);
|
$start = microtime(true);
|
||||||
mergeSort($array);
|
mergeSort($array);
|
||||||
$end = microtime(true);
|
$end = microtime(true);
|
||||||
@ -215,7 +213,7 @@ class SortingTests extends TestCase
|
|||||||
|
|
||||||
public function testQuickSortPerformance()
|
public function testQuickSortPerformance()
|
||||||
{
|
{
|
||||||
$array = range(1, 1000000);
|
$array = range(1, 1000);
|
||||||
$start = microtime(true);
|
$start = microtime(true);
|
||||||
quickSort($array);
|
quickSort($array);
|
||||||
$end = microtime(true);
|
$end = microtime(true);
|
||||||
@ -224,7 +222,7 @@ class SortingTests extends TestCase
|
|||||||
|
|
||||||
public function testRadixSortPerformance()
|
public function testRadixSortPerformance()
|
||||||
{
|
{
|
||||||
$array = range(1, 1000000);
|
$array = range(1, 10000);
|
||||||
$start = microtime(true);
|
$start = microtime(true);
|
||||||
radixSort($array);
|
radixSort($array);
|
||||||
$end = microtime(true);
|
$end = microtime(true);
|
||||||
@ -233,7 +231,7 @@ class SortingTests extends TestCase
|
|||||||
|
|
||||||
public function testSelectionSortPerformance()
|
public function testSelectionSortPerformance()
|
||||||
{
|
{
|
||||||
$array = range(1, 1000000);
|
$array = range(1, 1000);
|
||||||
$start = microtime(true);
|
$start = microtime(true);
|
||||||
selectionSort($array);
|
selectionSort($array);
|
||||||
$end = microtime(true);
|
$end = microtime(true);
|
||||||
@ -247,8 +245,8 @@ class SortingTests extends TestCase
|
|||||||
$secondArray = array(-6, 12, 14, 17, 5, 4, -9, 15, 0, -8);
|
$secondArray = array(-6, 12, 14, 17, 5, 4, -9, 15, 0, -8);
|
||||||
$expectedResultTwo = array(-9, -8, -6, 0, 4, 5, 12, 14, 15, 17);
|
$expectedResultTwo = array(-9, -8, -6, 0, 4, 5, 12, 14, 15, 17);
|
||||||
|
|
||||||
$resultOne = countSort($firstArray, $minRange = -10, $maxRange = 20);
|
$resultOne = countSort($firstArray);
|
||||||
$resultTwo = countSort($secondArray, $minRange = -10, $maxRange = 20);
|
$resultTwo = countSort($secondArray);
|
||||||
|
|
||||||
$this->assertEquals($expectedResultOne, $resultOne);
|
$this->assertEquals($expectedResultOne, $resultOne);
|
||||||
$this->assertEquals($expectedResultTwo, $resultTwo);
|
$this->assertEquals($expectedResultTwo, $resultTwo);
|
||||||
@ -271,7 +269,7 @@ class SortingTests extends TestCase
|
|||||||
|
|
||||||
public function testHeapSortPerformance()
|
public function testHeapSortPerformance()
|
||||||
{
|
{
|
||||||
$array = range(1, 1000000);
|
$array = range(1, 10000);
|
||||||
shuffle($array); // Randomize the order
|
shuffle($array); // Randomize the order
|
||||||
$start = microtime(true);
|
$start = microtime(true);
|
||||||
heapSort($array);
|
heapSort($array);
|
Reference in New Issue
Block a user