예제 #1
0
 /**
  * @dataProvider compareProvider
  */
 public function testCompare(DecimalValue $a, DecimalValue $b, $expected)
 {
     $actual = $a->compare($b);
     $this->assertSame($expected, $actual);
     $actual = $b->compare($a);
     $this->assertSame(-$expected, $actual);
 }
예제 #2
0
 /**
  * Constructs a new QuantityValue object, representing the given value.
  *
  * @since 0.1
  *
  * @param DecimalValue $amount
  * @param string $unit A unit identifier. Must not be empty, use "1" for unit-less quantities.
  * @param DecimalValue $upperBound The upper bound of the quantity, inclusive.
  * @param DecimalValue $lowerBound The lower bound of the quantity, inclusive.
  *
  * @throws IllegalValueException
  */
 public function __construct(DecimalValue $amount, $unit, DecimalValue $upperBound, DecimalValue $lowerBound)
 {
     if ($lowerBound->compare($amount) > 0) {
         throw new IllegalValueException('$lowerBound ' . $lowerBound->getValue() . ' must be <= $amount ' . $amount->getValue());
     }
     if ($upperBound->compare($amount) < 0) {
         throw new IllegalValueException('$upperBound ' . $upperBound->getValue() . ' must be >= $amount ' . $amount->getValue());
     }
     if (!is_string($unit)) {
         throw new IllegalValueException('$unit needs to be a string, not ' . gettype($unit));
     }
     if ($unit === '') {
         throw new IllegalValueException('$unit can not be an empty string (use "1" for unit-less quantities)');
     }
     $this->amount = $amount;
     $this->unit = $unit;
     $this->upperBound = $upperBound;
     $this->lowerBound = $lowerBound;
 }