Exemplo n.º 1
0
 /**
  * This method tests the "add" method.
  *
  * @dataProvider data_add
  */
 public function test_add(array $provided, array $expected)
 {
     $p0 = IDouble\Module::add(IDouble\Type::box($provided[0]), IDouble\Type::box($provided[1]));
     $e0 = $expected[0];
     $this->assertInstanceOf('\\Saber\\Data\\IDouble\\Type', $p0);
     $this->assertSame($e0, $p0->unbox());
 }
Exemplo n.º 2
0
 /**
  * This method returns a list of all numbers for the specified sequence.
  *
  * @access public
  * @static
  * @param IDouble\Type $x                                   where to start
  * @param Core\Type $y                                      either an integer representing
  *                                                          the end of the sequence or a
  *                                                          tuple describing the sequence
  * @return IArrayList\Type                                  an empty array list
  */
 public static function sequence(IDouble\Type $x, Core\Type $y) : IArrayList\Type
 {
     $buffer = array();
     if ($y instanceof ITuple\Type) {
         $s = IDouble\Module::subtract($y->first(), $x);
         $n = $y->second();
     } else {
         // ($y instanceof IDouble\Type)
         $s = IDouble\Type::one();
         $n = $y;
     }
     if (IDouble\Module::isNegative($s)->unbox()) {
         for ($i = $x; IDouble\Module::ge($i, $n)->unbox(); $i = IDouble\Module::add($i, $s)) {
             $buffer[] = $i;
         }
     } else {
         for ($i = $x; IDouble\Module::le($i, $n)->unbox(); $i = IDouble\Module::add($i, $s)) {
             $buffer[] = $i;
         }
     }
     return IArrayList\Type::box($buffer);
 }
Exemplo n.º 3
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());
 }