/** * @param array $precision * @param int $expectedMinInclusive * @param int $expectedMaxExclusive * @dataProvider randomDecimalCases */ public function testCreateRandomDecimal($precision, $expectedMinInclusive, $expectedMaxExclusive) { list($sigFigs, $decFigs) = $precision; for ($i = 0; $i < 10; $i++) { $decimal = CRM_Utils_Number::createRandomDecimal($precision); // print "Assert $decimal between $expectedMinInclusive and $expectedMaxExclusive\n"; $this->assertTrue($expectedMinInclusive <= $decimal && $decimal < $expectedMaxExclusive, "Assert {$decimal} between {$expectedMinInclusive} and {$expectedMaxExclusive}"); if (strpos($decimal, '.') === FALSE) { $decimal .= '.'; } list($before, $after) = explode('.', $decimal); $this->assertTrue(strlen($before) + strlen($after) <= $sigFigs, "Assert {$decimal} [{$before};{$after}] has <= {$sigFigs} sigFigs"); $this->assertTrue(strlen($after) <= $decFigs, "Assert {$decimal} [{$before};{$after}] has <= {$decFigs} decFigs"); } }