Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initialize unit tests #2

Closed
wants to merge 3 commits into from
Closed

Conversation

peter279k
Copy link

@peter279k peter279k commented May 2, 2018

Changed log

@peter279k peter279k changed the title Initial unit tests Initialize unit tests May 2, 2018
Copy link
Member

@dktapps dktapps left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've given this an initial glance-over.

src/Vector3.php Outdated
@@ -115,6 +115,10 @@ public function multiply(float $number) : Vector3{
}

public function divide(float $number) : Vector3{
if($number === 0.0){
throw new \InvalidArgumentException('Division by zero');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't necessary - PHP 7.x will raise a DivisionByZeroError.

src/Vector2.php Outdated
@@ -99,6 +99,10 @@ public function multiply(float $number) : Vector2{
}

public function divide(float $number) : Vector2{
if($number === 0.0){
throw new \InvalidArgumentException('Division by zero');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't necessary - PHP 7.x will raise a DivisionByZeroError.

src/Math.php Outdated
@@ -57,6 +57,9 @@ public static function solveQuadratic(float $a, float $b, float $c) : array{
(-$b - $sqrtDiscriminant) / (2 * $a)
];
}elseif($discriminant == 0){ //1 real root
if($a === 0.0){
throw new \InvalidArgumentException('Division by zero');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't necessary - PHP 7.x will raise a DivisionByZeroError.

composer.json Outdated
},
},
"require-dev": {
"phpunit/phpunit": "^6.5"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We prefer using a phar for PHPUnit. Also, this can be raised to PHPUnit 7 since this library is strictly PHP 7.2 and upwards only.

public function testConstructor(){
$axis = new AxisAlignedBB(1.1, 1.2, 1.3, 2.1, 2.2, 2.3);

$this->assertInstanceOf(AxisAlignedBB::class, $axis);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems redundant. new ... will always return an instance of that object - we're not working with extensions here.

$this->assertSame($expectedValue, $axis->intersectsWith($bb, $epsilon));
}

public function testGetApverageEdgeLength(){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

misspelling here

tests/Math.php Outdated
/**
* Class for the Math abstract class
*/
class Math extends MathAbstract{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I see the point of this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Firstly I create the pocketmine\math\tests\Math class and let it extend the pocketmine\math\Math class to let pocketmine\math\tests\MathTest can do unit test for the abstract class pocketmine\math\Math.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see why this is necessary - it's not instantiated anyway.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To do the unit test for pocketmine\math\Math, I think it should instantiate.
Otherwise it will not do this unit test.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test is not instantiating the Math class anywhere - it's only ever used for static function access. Excuse me if I'm missing the point, but this class is not instantiated anywhere I can see in these tests.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This Math class is used in the MathTest class.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... but you still don't instantiate it, you only statically access its methods.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your explanation and I know that.
I remove those non-instantiate abstract classes.

}

public function testSolveQuadraticThrowsInvalidArgumentException(){
$this->expectException(\InvalidArgumentException::class);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be changed to DivisionByZeroError (see above).

public function testConstructor(){
$matrix = new Matrix(1, 2);

$this->assertSame(1, $matrix->getRows());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure why assert that the row count is correct but not the column count? seems like a logic hole.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, I add the getColumn to assert the matrix column :-).

$hitVector = new Vector3(1.2, 1.3, 1.5);
$rayTraceResult = new RayTraceResult($bb, 1, $hitVector);

$this->assertInstanceOf(RayTraceResult::class, $rayTraceResult);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again, redundant.

@dktapps dktapps closed this Dec 6, 2021
@peter279k
Copy link
Author

It seems that this PR is outdated. Can I recreate this PR to let @dktapps review?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants