Beispiel #1
0
 /**
  * This method tests the "nvl" method.
  */
 public function test_nvl()
 {
     $x = IDouble\Type::one();
     $y = IDouble\Type::zero();
     $z = IDouble\Module::nvl($x, $y);
     $this->assertInstanceOf('\\Saber\\Data\\IDouble\\Type', $z);
     $this->assertSame(1.0, $z->unbox());
     $z = IDouble\Module::nvl(null, $x);
     $this->assertInstanceOf('\\Saber\\Data\\IDouble\\Type', $z);
     $this->assertSame(1.0, $z->unbox());
     $z = IDouble\Module::nvl(null, null);
     $this->assertInstanceOf('\\Saber\\Data\\IDouble\\Type', $z);
     $this->assertSame(0.0, $z->unbox());
 }
Beispiel #2
0
 /**
  * This method tests the "singletons" methods.
  */
 public function test_singletons()
 {
     $p0 = IDouble\Type::negative();
     $e0 = IDouble\Type::negative();
     $this->assertInstanceOf('\\Saber\\Data\\IDouble\\Type', $p0);
     $this->assertSame($e0->__hashCode(), $p0->__hashCode());
     $p1 = $p0->unbox();
     $e1 = -1.0;
     $this->assertInternalType('float', $p1);
     $this->assertSame($e1, $p1);
     $p2 = IDouble\Type::zero();
     $e2 = IDouble\Type::zero();
     $this->assertInstanceOf('\\Saber\\Data\\IDouble\\Type', $p2);
     $this->assertSame($e2->__hashCode(), $p2->__hashCode());
     $p3 = $p2->unbox();
     $e3 = 0.0;
     $this->assertInternalType('float', $p3);
     $this->assertSame($e3, $p3);
     $p4 = IDouble\Type::one();
     $e4 = IDouble\Type::one();
     $this->assertInstanceOf('\\Saber\\Data\\IDouble\\Type', $p4);
     $this->assertSame($e4->__hashCode(), $p4->__hashCode());
     $p5 = $p4->unbox();
     $e5 = 1.0;
     $this->assertInternalType('float', $p5);
     $this->assertSame($e5, $p5);
 }
Beispiel #3
0
 /**
  * This method returns the latter value should the former value evaluates
  * to null.
  *
  * @access public
  * @static
  * @param IDouble\Type $x                                   the value to be evaluated
  * @param IDouble\Type $y                                   the default value
  * @return IDouble\Type                                     the result
  */
 public static function nvl(IDouble\Type $x = null, IDouble\Type $y = null) : IDouble\Type
 {
     return $x ?? $y ?? IDouble\Type::zero();
 }
Beispiel #4
0
 /**
  * This method returns the sum of all items in the list.
  *
  * @access public
  * @static
  * @param ISeq\Type $xs                                     the sequence to be processed
  * @return IDouble\Type                                     the result
  */
 public static function sum(ISeq\Type $xs) : IDouble\Type
 {
     return $xs->foldLeft(function (IDouble\Type $c, INumber\Type $x) {
         return IDouble\Module::add($c, $x->toDouble());
     }, IDouble\Type::zero());
 }