Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions src/helper/CustomDataProvider.php

Large diffs are not rendered by default.

15 changes: 3 additions & 12 deletions tests/BinaryTreeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Src\BinaryTree;
use Src\helper\CustomDataProvider;

final class BinaryTreeTest extends TestCase
{
Expand All @@ -24,15 +25,7 @@ public function it_should_return_the_sorted_array(array $arr): void
*/
public static function arrayProvider(): array
{
return [
[[1, 2, 3, 4, 5, 6, 7, 8, 9]],
[[9, 8, 7, 6, 5, 4, 3, 2, 1]],
[[1, 2, 3, 9, 8, 7, 6, 5, 4]],
[[9, 8, 7, 1, 2, 3, 4, 5, 6]],
[[9, 1, 8, 2, 7, 3, 6, 4, 5]],
[[1, 9, 2, 8, 3, 7, 4, 6, 5]],
[[6, 4, 1, 8, 3, 9, 2, 5, 7]],
];
return CustomDataProvider::oneToNine();
}

#[Test]
Expand All @@ -56,8 +49,6 @@ public function it_should_sort_non_consecutive_numbers_correctly(): void
#[Test]
public function it_can_sort_array_with_1000_elements(): void
{
$random = range(1, 1000);
shuffle($random);
$this->assertEquals(range(1, 1000), BinaryTree::sort($random));
$this->assertEquals(range(1, 999), BinaryTree::sort(CustomDataProvider::oneToNineNineNine()[0][0]));
}
}
21 changes: 7 additions & 14 deletions tests/BubblesortTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Src\Bubblesort;
use Src\helper\CustomDataProvider;

final class BubblesortTest extends TestCase
{
#[Test]
#[DataProvider('arrayProvider')]
public function it_should_return_the_sorted_array($arr)
public function it_should_return_the_sorted_array(array $arr): void
{
$this->assertEquals([1,2,3,4,5,6,7,8,9], Bubblesort::sort($arr));
}

#[Test]
#[DataProvider('variantProvider')]
public function it_should_return_the_sorted_array_for_variants($variant)
public function it_should_return_the_sorted_array_for_variants(string $variant): void
{
$this->assertEquals([1,2,3,4,5,6,7,8,9], Bubblesort::sort([9,5,6,8,3,2,1,4,7], $variant));
}
Expand All @@ -28,15 +29,7 @@ public function it_should_return_the_sorted_array_for_variants($variant)
*/
public static function arrayProvider(): array
{
return [
[[1,2,3,4,5,6,7,8,9]],
[[9,8,7,6,5,4,3,2,1]],
[[1,2,3,9,8,7,6,5,4]],
[[9,8,7,1,2,3,4,5,6]],
[[9,1,8,2,7,3,6,4,5]],
[[1,9,2,8,3,7,4,6,5]],
[[6,4,1,8,3,9,2,5,7]],
];
return CustomDataProvider::oneToNine();
}

/*
Expand All @@ -55,21 +48,21 @@ public static function variantProvider(): array

#[Test]
#[DataProvider('variantProvider')]
public function it_should_sort_single_element_array($variant)
public function it_should_sort_single_element_array(string $variant): void
{
$this->assertEquals([4], Bubblesort::sort([4], $variant));
}

#[Test]
#[DataProvider('variantProvider')]
public function test_empty_array($variant)
public function test_empty_array(string $variant): void
{
$this->assertEquals([], Bubblesort::sort([], $variant));
}

#[Test]
#[DataProvider('variantProvider')]
public function it_should_sort_non_consecutive_numbers_correctly($variant)
public function it_should_sort_non_consecutive_numbers_correctly(string $variant): void
{
$this->assertEquals([2,5,6,8,9], Bubblesort::sort([5,9,6,2,8], $variant));
}
Expand Down
11 changes: 2 additions & 9 deletions tests/GnomesortTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Src\Gnomesort;
use Src\helper\CustomDataProvider;

final class GnomesortTest extends TestCase
{
Expand All @@ -24,15 +25,7 @@ public function it_should_return_the_sorted_array(array $arr): void
*/
public static function arrayProvider(): array
{
return [
[[1, 2, 3, 4, 5, 6, 7, 8, 9]],
[[9, 8, 7, 6, 5, 4, 3, 2, 1]],
[[1, 2, 3, 9, 8, 7, 6, 5, 4]],
[[9, 8, 7, 1, 2, 3, 4, 5, 6]],
[[9, 1, 8, 2, 7, 3, 6, 4, 5]],
[[1, 9, 2, 8, 3, 7, 4, 6, 5]],
[[6, 4, 1, 8, 3, 9, 2, 5, 7]],
];
return CustomDataProvider::oneToNine();
}

#[Test]
Expand Down
18 changes: 5 additions & 13 deletions tests/InsertionsortTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Src\helper\CustomDataProvider;
use Src\InsertionSort;

final class InsertionsortTest extends TestCase
Expand All @@ -26,15 +27,7 @@ public function it_should_return_the_sorted_array(array $arr): void
*/
public static function arrayProvider(): array
{
return [
[[1, 2, 3, 4, 5, 6, 7, 8, 9]],
[[9, 8, 7, 6, 5, 4, 3, 2, 1]],
[[1, 2, 3, 9, 8, 7, 6, 5, 4]],
[[9, 8, 7, 1, 2, 3, 4, 5, 6]],
[[9, 1, 8, 2, 7, 3, 6, 4, 5]],
[[1, 9, 2, 8, 3, 7, 4, 6, 5]],
[[6, 4, 1, 8, 3, 9, 2, 5, 7]],
];
return CustomDataProvider::oneToNine();
}

#[Test]
Expand All @@ -61,9 +54,8 @@ public function it_should_sort_non_consecutive_numbers_correctly(): void
#[Test]
public function it_can_sort_array_with_1000_elements(): void
{
$random = range(1, 1000);
shuffle($random);
$this->assertEquals(range(1, 1000), InsertionSort::sort($random));
$this->assertEquals(range(1, 1000), InsertionSort::sort($random, "variant2"));
$random = CustomDataProvider::oneToNineNineNine()[0][0];
$this->assertEquals(range(1, 999), InsertionSort::sort($random));
$this->assertEquals(range(1, 999), InsertionSort::sort($random, "variant2"));
}
}
26 changes: 9 additions & 17 deletions tests/MergeSortTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Src\helper\CustomDataProvider;
use Src\MergeSort;

final class MergeSortTest extends TestCase
{
#[Test]
#[DataProvider('arrayProvider')]
public function it_should_return_the_sorted_array($arr)
public function it_should_return_the_sorted_array($arr): void
{
$this->assertEquals([1,2,3,4,5,6,7,8,9], MergeSort::sort($arr));
}
Expand All @@ -21,40 +22,31 @@ public function it_should_return_the_sorted_array($arr)
*/
public static function arrayProvider(): array
{
return [
[[1,2,3,4,5,6,7,8,9]],
[[9,8,7,6,5,4,3,2,1]],
[[1,2,3,9,8,7,6,5,4]],
[[9,8,7,1,2,3,4,5,6]],
[[9,1,8,2,7,3,6,4,5]],
[[1,9,2,8,3,7,4,6,5]],
[[6,4,1,8,3,9,2,5,7]],
];
return CustomDataProvider::oneToNine();
}

#[Test]
public function it_should_sort_single_element_array()
public function it_should_sort_single_element_array(): void
{
$this->assertEquals([4], MergeSort::sort([4]));
}

#[Test]
public function test_empty_array()
public function test_empty_array(): void
{
$this->assertEquals([], MergeSort::sort([]));
}

#[Test]
public function it_should_sort_non_consecutive_numbers_correctly()
public function it_should_sort_non_consecutive_numbers_correctly(): void
{
$this->assertEquals([2,5,6,8,9], MergeSort::sort([5,9,6,2,8]));
}

#[Test]
public function it_can_sort_array_with_1000_elements()
public function it_can_sort_array_with_1000_elements(): void
{
$random = range(1, 1000);
shuffle($random);
$this->assertEquals(range(1, 1000), MergeSort::sort($random));
$random = CustomDataProvider::oneToNineNineNine()[0][0];
$this->assertEquals(range(1, 999), MergeSort::sort($random));
}
}
16 changes: 4 additions & 12 deletions tests/QuickSortTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Src\helper\CustomDataProvider;
use Src\QuickSort;

final class QuickSortTest extends TestCase
Expand All @@ -24,15 +25,7 @@ public function it_should_return_the_sorted_array(array $arr): void
*/
public static function arrayProvider(): array
{
return [
[[1, 2, 3, 4, 5, 6, 7, 8, 9]],
[[9, 8, 7, 6, 5, 4, 3, 2, 1]],
[[1, 2, 3, 9, 8, 7, 6, 5, 4]],
[[9, 8, 7, 1, 2, 3, 4, 5, 6]],
[[9, 1, 8, 2, 7, 3, 6, 4, 5]],
[[1, 9, 2, 8, 3, 7, 4, 6, 5]],
[[6, 4, 1, 8, 3, 9, 2, 5, 7]],
];
return CustomDataProvider::oneToNine();
}

#[Test]
Expand All @@ -56,8 +49,7 @@ public function it_should_sort_non_consecutive_numbers_correctly(): void
#[Test]
public function it_can_sort_array_with_1000_elements(): void
{
$random = range(1, 1000);
shuffle($random);
$this->assertEquals(range(1, 1000), QuickSort::sort($random));
$random = CustomDataProvider::oneToNineNineNine()[0][0];
$this->assertEquals(range(1, 999), QuickSort::sort($random));
}
}
26 changes: 9 additions & 17 deletions tests/ShakersortTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Src\helper\CustomDataProvider;
use Src\Shakersort;

final class ShakersortTest extends TestCase
{
#[Test]
#[DataProvider('arrayProvider')]
public function it_should_return_the_sorted_array($arr)
public function it_should_return_the_sorted_array($arr): void
{
$this->assertEquals([1,2,3,4,5,6,7,8,9], Shakersort::sort($arr));
}
Expand All @@ -21,40 +22,31 @@ public function it_should_return_the_sorted_array($arr)
*/
public static function arrayProvider(): array
{
return [
[[1,2,3,4,5,6,7,8,9]],
[[9,8,7,6,5,4,3,2,1]],
[[1,2,3,9,8,7,6,5,4]],
[[9,8,7,1,2,3,4,5,6]],
[[9,1,8,2,7,3,6,4,5]],
[[1,9,2,8,3,7,4,6,5]],
[[6,4,1,8,3,9,2,5,7]],
];
return CustomDataProvider::oneToNine();
}

#[Test]
public function it_should_sort_single_element_array()
public function it_should_sort_single_element_array(): void
{
$this->assertEquals([4], Shakersort::sort([4]));
}

#[Test]
public function test_empty_array()
public function test_empty_array(): void
{
$this->assertEquals([], Shakersort::sort([]));
}

#[Test]
public function it_should_sort_non_consecutive_numbers_correctly()
public function it_should_sort_non_consecutive_numbers_correctly(): void
{
$this->assertEquals([2,5,6,8,9], Shakersort::sort([5,9,6,2,8]));
}

#[Test]
public function it_can_sort_array_with_1000_elements()
public function it_can_sort_array_with_1000_elements(): void
{
$random = range(1, 1000);
shuffle($random);
$this->assertEquals(range(1, 1000), Shakersort::sort($random));
$random = CustomDataProvider::oneToNineNineNine()[0][0];
$this->assertEquals(range(1, 999), Shakersort::sort($random));
}
}
Loading