Exemplo n.º 1
0
 /**
  * This method tests the "add" method.
  *
  * @dataProvider data_add
  */
 public function test_add(array $provided, array $expected)
 {
     $p0 = IInt32\Module::add(IInt32\Type::box($provided[0]), IInt32\Type::box($provided[1]));
     $e0 = $expected[0];
     $this->assertInstanceOf('\\Saber\\Data\\IInt32\\Type', $p0);
     $this->assertEquals($e0, $p0->unbox());
 }
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()));
 }
Exemplo n.º 3
0
 /**
  * This method provides the data for testing the "foldRight" method.
  *
  * @return array
  */
 public function data_foldRight()
 {
     $predicate = function (IInt32\Type $c, IInt32\Type $x) : IInt32\Type {
         return IInt32\Module::add($c, $x);
     };
     $data = array(array(array(array(), $predicate), array(0)), array(array(array(1), $predicate), array(1)), array(array(array(1, 2), $predicate), array(3)), array(array(array(1, 2, 3), $predicate), array(6)), array(array(array(1, 2, 3, 4), $predicate), array(10)));
     return $data;
 }
Exemplo n.º 4
0
 /**
  * This method returns the result of incrementing this object's value.
  *
  * @access public
  * @static
  * @param IInt32\Type $x                                    the operand
  * @return IInt32\Type                                      the result
  */
 public static function increment(IInt32\Type $x) : IInt32\Type
 {
     return IInt32\Module::add($x, IInt32\Type::one());
 }
Exemplo n.º 5
0
 /**
  * This method returns the extracted slice of the list.
  *
  * @access public
  * @static
  * @param ILinkedList\Type $xs                              the left operand
  * @param IInt32\Type $offset                               the starting index
  * @param IInt32\Type $length                               the length of the slice
  * @return ILinkedList\Type                                 the list
  */
 public static function slice(ILinkedList\Type $xs, IInt32\Type $offset, IInt32\Type $length) : ILinkedList\Type
 {
     return ILinkedList\Module::drop(ILinkedList\Module::take($xs, IInt32\Module::add($length, $offset)), $offset);
 }