assertSame($result, $realLibraryResult, 'The actual function result should match the expected result'); $actual = \Yuloh\BcCompPolyfill\bccomp($leftOperand, $rightOperand, $scale); $this->assertSame($result, $actual, $msg); } /** * @expectedException PHPUnit_Framework_Error_Warning */ public function testInvalidScale() { \Yuloh\BcCompPolyfill\bccomp(1, 1, []); } public function fuzzTestData() { $data = []; for ($i = 0; $i < 1000; $i++) { $leftOperand = $this->randOperand(); $rightOperand = $this->randOperand(); $scale = rand(0, 200); $result = \bccomp($leftOperand, $rightOperand, $scale); $data[] = [$leftOperand, $rightOperand, $scale, $result]; } return $data; } /** * @dataProvider fuzzTestData */ public function testWithRandomData($leftOperand, $rightOperand, $scale, $result) { $actual = \Yuloh\BcCompPolyfill\bccomp($leftOperand, $rightOperand, $scale); $this->assertSame($result, $actual); } public function randOperand() { $negative = rand() % 2 === 0 ? '-' : ''; $characteristic = rand(); $mantissa = rand() % 2 === 0 ? '.' . rand() : ''; return $negative . $characteristic . $mantissa; } }