Exemplo n.º 1
0
 /**
  * This method tests the boxing of a boxed value.
  *
  * @dataProvider data_box
  */
 public function test_box(array $provided, array $expected)
 {
     //$this->markTestIncomplete();
     $p0 = IRatio\Type::box($provided[0], $provided[1]);
     $e0 = $expected;
     $this->assertInstanceOf('\\Saber\\Core\\Type', $p0);
     $this->assertInstanceOf('\\Saber\\Data\\Type', $p0);
     $this->assertInstanceOf('\\Saber\\Data\\IFractional\\Type', $p0);
     $this->assertInstanceOf('\\Saber\\Data\\IRatio\\Type', $p0);
     $pN = $p0->numerator();
     $pD = $p0->denominator();
     $eN = $e0[0]->unbox();
     $eD = $e0[1]->unbox();
     $this->assertInstanceOf('\\Saber\\Data\\IInt32\\Type', $pN);
     $this->assertInstanceOf('\\Saber\\Data\\IInt32\\Type', $pD);
     $this->assertSame($eN, $pN->unbox());
     $this->assertSame($eD, $pD->unbox());
     $p1 = $p0->unbox();
     $this->assertInternalType('array', $p1);
     $this->assertTrue(count($p1) == 2);
     $this->assertInstanceOf('\\Saber\\Data\\IInt32\\Type', $p1[0]);
     $this->assertInstanceOf('\\Saber\\Data\\IInt32\\Type', $p1[1]);
     $this->assertSame($eN, $p1[0]->unbox());
     $this->assertSame($eD, $p1[1]->unbox());
     $p2 = $p0->unbox(1);
     $this->assertInternalType('array', $p2);
     $this->assertTrue(count($p2) == 2);
     $this->assertInternalType('integer', $p2[0]);
     $this->assertInternalType('integer', $p2[1]);
     $this->assertSame($eN, $p2[0]);
     $this->assertSame($eD, $p2[1]);
 }
Exemplo n.º 2
0
 /**
  * This method returns the result of adding the specified value to this object's value.
  *
  * @access public
  * @static
  * @param IRatio\Type $x                                    the left operand
  * @param IRatio\Type $y                                    the right operand
  * @return IRatio\Type                                      the result
  */
 public static function add(IRatio\Type $x, IRatio\Type $y) : IRatio\Type
 {
     if (IInt32\Module::signum($y->numerator())->unbox() == 0) {
         return $x;
     }
     if (IInt32\Module::signum($x->numerator())->unbox() == 0) {
         return $y;
     }
     if (IInt32\Module::eq($x->denominator(), $y->denominator())->unbox()) {
         return IRatio\Type::box(IInt32\Module::add($x->numerator(), $y->numerator()), $x->denominator());
     }
     return IRatio\Type::make(IInt32\Module::add(IInt32\Module::multiply($x->numerator(), $y->denominator()), IInt32\Module::multiply($y->numerator(), $x->denominator())), IInt32\Module::multiply($x->denominator(), $y->denominator()));
 }