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