コード例 #1
0
ファイル: TypeTest.php プロジェクト: bluesnowman/fphp-saber
 /**
  * This method tests the making of a boxed value.
  *
  * @dataProvider data_make
  */
 public function test_make(array $provided, array $expected)
 {
     //$this->markTestIncomplete();
     $p0 = IRatio\Type::make($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]);
 }
コード例 #2
0
ファイル: Module.php プロジェクト: bluesnowman/fphp-saber
 /**
  * This method returns the reciprocal.
  *
  * @access public
  * @static
  * @param IRatio\Type $x                                    the ratio to be inverted
  * @return IRatio\Type                                      the reciprocal
  */
 public static function invert(IRatio\Type $x) : IRatio\Type
 {
     return IRatio\Type::make($x->denominator(), $x->numerator());
 }