Skip to content

Commit

Permalink
Merge branch 'enum' of https://github.com/Dhaiven/Math into enum
Browse files Browse the repository at this point in the history
  • Loading branch information
Dhaiven committed May 12, 2024
2 parents 1c1a45e + 0e132c9 commit 89f49e0
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 66 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ jobs:
if: "!contains(github.event.head_commit.message, '[ci skip]')"
strategy:
matrix:
php: ['8.0', '8.1']
php: ['8.1', '8.2', '8.3']
name: PHP ${{ matrix.php }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@2.9.0
uses: shivammathur/setup-php@2.29.0
with:
php-version: ${{ matrix.php }}

- name: Cache Composer packages
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: "~/.cache/composer"
key: "php-${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}-v2"
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
"type": "library",
"license": "LGPL-3.0",
"require": {
"php": "^8.0",
"php": "^8.1",
"php-64bit": "*"
},
"require-dev": {
"phpstan/phpstan": "~1.10.3",
"phpstan/extension-installer": "^1.0",
"phpstan/phpstan-strict-rules": "^1.0",
"phpunit/phpunit": "^8.5 || ^9.5"
"phpunit/phpunit": "^10.0 || ^11.0"
},
"autoload": {
"psr-4": {
Expand Down
39 changes: 9 additions & 30 deletions tests/phpunit/FacingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@

namespace pocketmine\math;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

class FacingTest extends TestCase{

public function axisProvider() : \Generator{
public static function axisProvider() : \Generator{
yield [Facing::DOWN, Axis::Y];
yield [Facing::UP, Axis::Y];
yield [Facing::NORTH, Axis::Z];
Expand All @@ -34,34 +35,24 @@ public function axisProvider() : \Generator{
yield [Facing::EAST, Axis::X];
}

/**
* @dataProvider axisProvider
*
* @param Facing $facing
* @param Axis $axis
*/
#[DataProvider("axisProvider")]
public function testAxis(Facing $direction, Axis $axis) : void{
self::assertEquals($axis, Facing::axis($direction));
}

public function oppositeProvider() : \Generator{
public static function oppositeProvider() : \Generator{
yield [Facing::DOWN, Facing::UP];
yield [Facing::NORTH, Facing::SOUTH];
yield [Facing::WEST, Facing::EAST];
}

/**
* @dataProvider oppositeProvider
*
* @param Facing $dir1
* @param Facing $dir2
*/
#[DataProvider("oppositeProvider")]
public function testOpposite(Facing $dir1, Facing $dir2) : void{
self::assertEquals($dir2, Facing::opposite($dir1));
self::assertEquals($dir1, Facing::opposite($dir2));
}

public function positiveProvider() : \Generator{
public static function positiveProvider() : \Generator{
yield [Facing::DOWN, false];
yield [Facing::UP, true];
yield [Facing::NORTH, false];
Expand All @@ -70,17 +61,12 @@ public function positiveProvider() : \Generator{
yield [Facing::EAST, true];
}

/**
* @dataProvider positiveProvider
*
* @param Facing $facing
* @param bool $positive
*/
#[DataProvider("positiveProvider")]
public function testIsPositive(Facing $facing, bool $positive) : void{
self::assertEquals($positive, Facing::isPositive($facing));
}

public function rotateProvider() : \Generator{
public static function rotateProvider() : \Generator{
yield [Facing::NORTH, Axis::Y, true, Facing::EAST];
yield [Facing::EAST, Axis::Y, true, Facing::SOUTH];
yield [Facing::SOUTH, Axis::Y, true, Facing::WEST];
Expand Down Expand Up @@ -114,14 +100,7 @@ public function rotateProvider() : \Generator{
yield [Facing::NORTH, Axis::X, false, Facing::UP];
}

/**
* @dataProvider rotateProvider
*
* @param Facing $direction
* @param Axis $axis
* @param bool $clockwise
* @param Facing $expected
*/
#[DataProvider("rotateProvider")]
public function testRotate(Facing $direction, Axis $axis, bool $clockwise, Facing $expected) : void{
self::assertEquals($expected, Facing::rotate($direction, $axis, $clockwise));
}
Expand Down
40 changes: 10 additions & 30 deletions tests/phpunit/Vector3Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@

namespace pocketmine\math;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

class Vector3Test extends TestCase{

public function minComponentsProvider() : \Generator{
public static function minComponentsProvider() : \Generator{
yield [
new Vector3(1, 2, 3),
new Vector3(9, 8, 7),
Expand All @@ -52,19 +53,12 @@ public function minComponentsProvider() : \Generator{
];
}

/**
* @dataProvider minComponentsProvider
*
* @param Vector3 $vec1
* @param Vector3 $vec2
* @param Vector3 $vec3
* @param Vector3 $expected
*/
#[DataProvider("minComponentsProvider")]
public function testMinComponents(Vector3 $vec1, Vector3 $vec2, Vector3 $vec3, Vector3 $expected) : void{
self::assertEquals(Vector3::minComponents($vec1, $vec2, $vec3), $expected);
}

public function maxComponentsProvider() : \Generator{
public static function maxComponentsProvider() : \Generator{
yield [
new Vector3(1, 2, 3),
new Vector3(9, 8, 7),
Expand All @@ -91,14 +85,7 @@ public function maxComponentsProvider() : \Generator{
];
}

/**
* @dataProvider maxComponentsProvider
*
* @param Vector3 $vec1
* @param Vector3 $vec2
* @param Vector3 $vec3
* @param Vector3 $expected
*/
#[DataProvider("maxComponentsProvider")]
public function testMaxComponents(Vector3 $vec1, Vector3 $vec2, Vector3 $vec3, Vector3 $expected) : void{
self::assertEquals(Vector3::maxComponents($vec1, $vec2, $vec3), $expected);
}
Expand All @@ -107,18 +94,17 @@ public function testMaxComponents(Vector3 $vec1, Vector3 $vec2, Vector3 $vec3, V
* @return \Generator|Vector3[][][]
* @phpstan-return \Generator<int, list<list<Vector3>>, void, void>
*/
public function sumProvider() : \Generator{
public static function sumProvider() : \Generator{
yield [[
new Vector3(1, 1, 1),
new Vector3(-1, -1, -1)
]];
}

/**
* @dataProvider sumProvider
*
* @param Vector3[] $vectors
*/
#[DataProvider("sumProvider")]
public function testSum(array $vectors) : void{
$vec = new Vector3(0, 0, 0);
foreach($vectors as $vector){
Expand All @@ -133,22 +119,16 @@ public function testSum(array $vectors) : void{
/**
* @phpstan-return \Generator<int, array{Vector3, float|int|null, float|int|null, float|int|null, Vector3}, void, void>
*/
public function withComponentsProvider() : \Generator{
public static function withComponentsProvider() : \Generator{
yield [new Vector3(0, 0, 0), 1, 1, 1, new Vector3(1, 1, 1)];
yield [new Vector3(0, 0, 0), null, 1, 1, new Vector3(0, 1, 1)];
yield [new Vector3(0, 0, 0), 1, null, 1, new Vector3(1, 0, 1)];
yield [new Vector3(0, 0, 0), 1, 1, null, new Vector3(1, 1, 0)];
yield [new Vector3(0, 0, 0), null, null, null, new Vector3(0, 0, 0)];
}

/**
* @dataProvider withComponentsProvider
*
* @param float|int|null $x
* @param float|int|null $y
* @param float|int|null $z
*/
public function testWithComponents(Vector3 $original, $x, $y, $z, Vector3 $expected) : void{
#[DataProvider("withComponentsProvider")]
public function testWithComponents(Vector3 $original, float|int|null $x, float|int|null $y, float|int|null $z, Vector3 $expected) : void{
$actual = $original->withComponents($x, $y, $z);
self::assertTrue($actual->equals($expected));
}
Expand Down

0 comments on commit 89f49e0

Please sign in to comment.