-
-
Notifications
You must be signed in to change notification settings - Fork 71
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
Fix mutations + math float tests #427
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -21,6 +21,48 @@ | |||||||||||||||||||||||
} | ||||||||||||||||||||||||
}, | ||||||||||||||||||||||||
"timeout": 10, | ||||||||||||||||||||||||
"minMsi": 98, | ||||||||||||||||||||||||
"minCoveredMsi": 100 | ||||||||||||||||||||||||
"minMsi": 100, | ||||||||||||||||||||||||
"minCoveredMsi": 100, | ||||||||||||||||||||||||
"mutators": { | ||||||||||||||||||||||||
"@default": true, | ||||||||||||||||||||||||
"Break_": { | ||||||||||||||||||||||||
"ignore": [ | ||||||||||||||||||||||||
"Psl\\Collection\\*Map::zip" | ||||||||||||||||||||||||
] | ||||||||||||||||||||||||
}, | ||||||||||||||||||||||||
"DecrementInteger": { | ||||||||||||||||||||||||
"ignore": [ | ||||||||||||||||||||||||
"Psl\\DataStructure\\PriorityQueue::peek" | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This fallback to
I could solve it by doing an additional |
||||||||||||||||||||||||
] | ||||||||||||||||||||||||
}, | ||||||||||||||||||||||||
"FunctionCallRemoval": { | ||||||||||||||||||||||||
"ignore": [ | ||||||||||||||||||||||||
"Psl\\Result\\Success::getThrowable" | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one is actually covered - yet infection doesnt seem to be able to link the test to the mutation. See psl/tests/unit/Result/SuccessTest.php Lines 34 to 42 in 4affb62
|
||||||||||||||||||||||||
] | ||||||||||||||||||||||||
}, | ||||||||||||||||||||||||
"IncrementInteger": { | ||||||||||||||||||||||||
"ignore": [ | ||||||||||||||||||||||||
"Psl\\DataStructure\\PriorityQueue::peek" | ||||||||||||||||||||||||
] | ||||||||||||||||||||||||
}, | ||||||||||||||||||||||||
"LogicalNot": { | ||||||||||||||||||||||||
"ignore": [ | ||||||||||||||||||||||||
"Psl\\Hash\\Context::update" | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hard to cover this one: Lines 74 to 79 in 4affb62
(the code coverage was already added as well.) |
||||||||||||||||||||||||
] | ||||||||||||||||||||||||
}, | ||||||||||||||||||||||||
"MethodCallRemoval": { | ||||||||||||||||||||||||
"ignore": [ | ||||||||||||||||||||||||
"Psl\\Iter\\Iterator::seek", | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These functions were added to speed up the tests : it results in time-outs cause the iterator does not iterate anymore because it removes: Line 181 in 4affb62
|
||||||||||||||||||||||||
"Psl\\Iter\\Iterator::count" | ||||||||||||||||||||||||
] | ||||||||||||||||||||||||
}, | ||||||||||||||||||||||||
"Throw_": { | ||||||||||||||||||||||||
"ignore": [ | ||||||||||||||||||||||||
"Psl\\File\\ReadHandle::__construct", | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've added some tests as well - but didnt want to go into chmodding files and testing for readability / writability at this moment. See psl/src/Psl/File/ReadHandle.php Lines 25 to 35 in 4affb62
|
||||||||||||||||||||||||
"Psl\\File\\WriteHandle::__construct", | ||||||||||||||||||||||||
"Psl\\File\\ReadWriteHandle::__construct", | ||||||||||||||||||||||||
"Psl\\Hash\\Context::update" | ||||||||||||||||||||||||
] | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Psl\Tests\Unit\Math; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Psl\Math; | ||
|
||
trait FloatAsserts | ||
{ | ||
/** | ||
* Because not all systems have the same rounding rules and precisions, | ||
* This method provides an assertion to compare floats based on epsilon:. | ||
* | ||
* @see https://www.php.net/manual/en/language.types.float.php#language.types.float.comparison | ||
*/ | ||
public static function assertFloatEquals(float $a, float $b, float $epsilon = PHP_FLOAT_EPSILON): void | ||
{ | ||
TestCase::assertTrue( | ||
Math\abs($a - $b) <= $epsilon, | ||
'Failed asserting that float ' . $a . ' is equal to ' . $b . '.' | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,20 +9,23 @@ | |
|
||
final class TanTest extends TestCase | ||
{ | ||
use FloatAsserts; | ||
|
||
/** | ||
* @dataProvider provideData | ||
*/ | ||
public function testTan(float $expected, float $number): void | ||
public function testTan(float $expected, float $number, float $epsilon = PHP_FLOAT_EPSILON): void | ||
{ | ||
static::assertSame($expected, Math\tan($number)); | ||
static::assertFloatEquals($expected, Math\tan($number), $epsilon); | ||
} | ||
|
||
public function provideData(): array | ||
{ | ||
return [ | ||
[ | ||
-3.380515006246586, | ||
5.0 | ||
5.0, | ||
0.00000000000001 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it is off by one on my system for some odd reason. Therefor I decided to check only the first 14 digits |
||
], | ||
|
||
[ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the break gets transformed into a continue, it will produce the same output - yet slower.
So this is a false positive:
psl/src/Psl/Collection/Map.php
Lines 378 to 380 in 4affb62