/** * @dataProvider transformProvider */ public function testTransform(QuantityValue $quantity, $transformation, QuantityValue $expected) { $args = func_get_args(); $extraArgs = array_slice($args, 3); $call = array($quantity, 'transform'); $callArgs = array_merge(array('x', $transformation), $extraArgs); $actual = call_user_func_array($call, $callArgs); $this->assertEquals('x', $actual->getUnit()); $this->assertEquals($expected->getAmount()->getValue(), $actual->getAmount()->getValue(), 'value'); $this->assertEquals($expected->getUpperBound()->getValue(), $actual->getUpperBound()->getValue(), 'upper bound'); $this->assertEquals($expected->getLowerBound()->getValue(), $actual->getLowerBound()->getValue(), 'lower bound'); }
/** * Returns the rounding exponent based on the given $quantity * and the @see QuantityFormatter::OPT_APPLY_ROUNDING option. * * @param QuantityValue $quantity * * @return int */ private function getRoundingExponent(QuantityValue $quantity) { if ($this->options->getOption(self::OPT_APPLY_ROUNDING) === true) { // round to the order of uncertainty return $quantity->getOrderOfUncertainty(); } elseif ($this->options->getOption(self::OPT_APPLY_ROUNDING) === false) { // to keep all digits, use the negative length of the fractional part return -strlen($quantity->getAmount()->getFractionalPart()); } else { return (int) $this->options->getOption(self::OPT_APPLY_ROUNDING); } }