Skip to content

Commit

Permalink
Allow small numerical variance in unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewdalpino committed Sep 20, 2023
1 parent e06ebc8 commit 880c4ef
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 96 deletions.
1 change: 1 addition & 0 deletions benchmarks/Decompositions/CholeskyBench.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public function setUp() : void
}

/**
* @Skip
* @Subject
* @Iterations(5)
* @OutputTimeUnit("seconds", precision=3)
Expand Down
10 changes: 5 additions & 5 deletions phpbench.json.dist
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"bootstrap": "vendor/autoload.php",
"path": "benchmarks",
"time_unit": "seconds",
"progress": "blinken",
"php_config": {
"runner.bootstrap": "vendor/autoload.php",
"runner.path": "benchmarks",
"runner.time_unit": "seconds",
"runner.progress": "blinken",
"runner.php_config": {
"memory_limit": "-1"
}
}
15 changes: 11 additions & 4 deletions tests/ColumnVectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@
*/
class ColumnVectorTest extends TestCase
{
/**
* The maximum error tolerated due to varying numerical precision.
*
* @var float
*/
protected const MAX_DELTA = 1e-8;

/**
* @test
*/
Expand Down Expand Up @@ -108,7 +115,7 @@ public function multiply() : void
[38.5, 175, -175],
]);

$this->assertEquals($expected, $c);
$this->assertEqualsWithDelta($expected, $c, self::MAX_DELTA);
}

/**
Expand All @@ -132,7 +139,7 @@ public function divide() : void
[31.818181818181817, 7, -7],
]);

$this->assertEquals($expected, $c);
$this->assertEqualsWithDelta($expected, $c, self::MAX_DELTA);
}

/**
Expand All @@ -156,7 +163,7 @@ public function add() : void
[36.1, 40, 30],
]);

$this->assertEquals($expected, $c);
$this->assertEqualsWithDelta($expected, $c, self::MAX_DELTA);
}

/**
Expand All @@ -180,7 +187,7 @@ public function subtract() : void
[33.9, 30, 40],
]);

$this->assertEquals($expected, $c);
$this->assertEqualsWithDelta($expected, $c, self::MAX_DELTA);
}

/**
Expand Down
Loading

0 comments on commit 880c4ef

Please sign in to comment.