Ejemplo n.º 1
0
 /**
  * This method tests the "item" method.
  *
  * @dataProvider data_item
  */
 public function test_item(array $provided, array $expected)
 {
     $p0 = ITuple\Type::make($provided[0]);
     $e0 = $expected[0];
     foreach ($e0 as $i => $e) {
         $this->assertSame($e, $p0->item(IInt32\Type::box($i))->unbox());
     }
 }
Ejemplo n.º 2
0
 /**
  * This method returns a value as a boxed object.  A value is typically a PHP typed
  * primitive or object.  It is considered "not" type-safe.
  *
  * @access public
  * @static
  * @param mixed $value                                      the value(s) to be boxed
  * @return IRatio\Type                                      the boxed object
  */
 public static function box($value) : IRatio\Type
 {
     $values = is_array($value) ? $value : func_get_args();
     $values = array_map(function ($value) {
         return $value instanceof IInt32\Type ? $value : IInt32\Type::box($value);
     }, $values);
     return new IRatio\Type($values[0], $values[1]);
 }
Ejemplo n.º 3
0
 /**
  * This method tests the data type.
  */
 public function test_instanceOf()
 {
     //$this->markTestIncomplete();
     $p0 = new IRatio\Type(IInt32\Type::one(), IInt32\Type::box(2));
     $this->assertInstanceOf('\\Saber\\Data\\IRatio\\Type', $p0);
     $this->assertInstanceOf('\\Saber\\Data\\IFractional\\Type', $p0);
     $this->assertInstanceOf('\\Saber\\Data\\INumber\\Type', $p0);
     $this->assertInstanceOf('\\Saber\\Data\\Type', $p0);
     $this->assertInstanceOf('\\Saber\\Core\\Equality\\Type', $p0);
     $this->assertInstanceOf('\\Saber\\Core\\Comparable\\Type', $p0);
     $this->assertInstanceOf('\\Saber\\Core\\Boxable\\Type', $p0);
     $this->assertInstanceOf('\\JsonSerializable', $p0);
     $this->assertInstanceOf('\\Saber\\Core\\Type', $p0);
 }
Ejemplo n.º 4
0
 /**
  * This method tests the "toString" method.
  *
  * @dataProvider data_toString
  */
 public function test_toString(array $provided, array $expected)
 {
     $p0 = IEither\Type::left(IInt32\Type::box($provided[0]))->toString();
     $e0 = $expected[0];
     $this->assertInstanceOf('\\Saber\\Data\\IString\\Type', $p0);
     $this->assertSame($e0, $p0->unbox());
     $p1 = IEither\Type::right(IInt32\Type::box($provided[0]))->toString();
     $e1 = $expected[0];
     $this->assertInstanceOf('\\Saber\\Data\\IString\\Type', $p1);
     $this->assertSame($e1, $p1->unbox());
 }
Ejemplo n.º 5
0
 /**
  * This method returns the size of this collection.
  *
  * @access public
  * @final
  * @return IInt32\Type                                      the size of this collection
  */
 public final function size() : IInt32\Type
 {
     return IInt32\Type::box($this->__size());
 }
Ejemplo n.º 6
0
 /**
  * This method returns the length of this array list.
  *
  * @access public
  * @final
  * @return IInt32\Type                                      the length of this array list
  */
 public final function length() : IInt32\Type
 {
     return IInt32\Type::box($this->__length());
 }
Ejemplo n.º 7
0
 /**
  * This method returns a list of all numbers for the specified sequence.
  *
  * @access public
  * @static
  * @param IInt32\Type $x                                    where to start
  * @param Core\Boxable\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(IInt32\Type $x, Core\Boxable\Type $y) : IArrayList\Type
 {
     if ($y instanceof ITuple\Type) {
         $s = $y->first();
         $n = $y->second();
     } else {
         $s = IInt32\Type::one();
         $n = $y;
     }
     return IArrayList\Type::box(array_map(function (int $value) : IInt32\Type {
         return IInt32\Type::box($value);
     }, range($x->unbox(), $n->unbox(), $s->unbox())));
 }
Ejemplo n.º 8
0
 /**
  * This method evaluates whether the left operand is identical to the right operand.
  *
  * @access public
  * @static
  * @param IArrayList\Type $xs                               the left operand
  * @param Core\Type $ys                                     the right operand
  * @return IBool\Type                                       whether the left operand is identical
  *                                                          to the right operand
  */
 public static function id(IArrayList\Type $xs, Core\Type $ys) : IBool\Type
 {
     // ===
     if ($ys !== null) {
         if ($xs->__typeOf() === $ys->__typeOf()) {
             $x_length = $xs->__length();
             $y_length = $ys->__length();
             for ($i = 0; $i < $x_length && $i < $y_length; $i++) {
                 $p = IInt32\Type::box($i);
                 $r = $xs->item($p)->id($ys->item($p));
                 if (!$r->unbox()) {
                     return $r;
                 }
             }
             return IBool\Type::box($x_length == $y_length);
         }
     }
     return IBool\Type::false();
 }
Ejemplo n.º 9
0
 /**
  * This method tests the "take" method.
  *
  * @dataProvider data_take
  */
 public function test_take(array $provided, array $expected)
 {
     $p0 = ILinkedList\Type::make($provided[0], '\\Saber\\Data\\IInt32\\Type');
     $p1 = IInt32\Type::box($provided[1]);
     $r0 = ILinkedList\Module::take($p0, $p1);
     $e0 = $expected[0];
     $this->assertInstanceOf('\\Saber\\Data\\ILinkedList\\Type', $r0);
     $this->assertSame($e0, $r0->unbox(1));
 }
Ejemplo n.º 10
0
 /**
  * This method tests the "isOdd" method.
  *
  * @dataProvider data_isOdd
  */
 public function test_isOdd(array $provided, array $expected)
 {
     $p0 = IInt32\Module::isOdd(IInt32\Type::box($provided[0]));
     $e0 = $expected[0];
     $this->assertInstanceOf('\\Saber\\Data\\IBool\\Type', $p0);
     $this->assertSame($e0, $p0->unbox());
 }
Ejemplo n.º 11
0
 /**
  * This method tests the "toString" method.
  *
  * @dataProvider data_toString
  */
 public function test_toString(array $provided, array $expected)
 {
     $p0 = IOption\Type::some(IInt32\Type::box($provided[0]))->toString();
     $e0 = $expected[0];
     $this->assertInstanceOf('\\Saber\\Data\\IString\\Type', $p0);
     $this->assertSame($e0, $p0->unbox());
 }
Ejemplo n.º 12
0
 /**
  * This method tests the "pow" method.
  *
  * @dataProvider data_pow
  */
 public function test_pow(array $provided, array $expected)
 {
     $p0 = IFloat\Module::pow(IFloat\Type::box($provided[0]), IInt32\Type::box($provided[1]));
     $e0 = $expected[0];
     $this->assertInstanceOf('\\Saber\\Data\\IFloat\\Type', $p0);
     $this->assertSame($e0, $p0->unbox());
 }
Ejemplo n.º 13
0
 /**
  * This method tests the "item" related methods.
  */
 public function test_items()
 {
     $p0 = IString\Type::box('012');
     $this->assertSame('0', $p0->item(IInt32\Type::zero())->unbox());
     $this->assertSame('1', $p0->item(IInt32\Type::one())->unbox());
     $this->assertSame('2', $p0->item(IInt32\Type::box(2))->unbox());
     $this->assertSame('0', $p0->head()->unbox());
     $p1 = $p0->tail();
     $this->assertInstanceOf('\\Saber\\Data\\IString\\Type', $p1);
     $this->assertSame('12', $p1->unbox());
 }
Ejemplo n.º 14
0
 /**
  * This method provides the data for testing that a value is of a particular size.
  *
  * @return array
  */
 public function dataSize()
 {
     $data = array(array(array(), array(0)), array(array(IInt32\Type::zero()), array(1)), array(array(IInt32\Type::zero(), IInt32\Type::one(), IInt32\Type::box(2)), array(3)), array(array(IInt32\Type::zero(), IInt32\Type::zero(), IInt32\Type::zero()), array(1)), array(array(IInt32\Type::zero(), IInt32\Type::zero(), IInt32\Type::one(), IInt32\Type::one()), array(2)));
     return $data;
 }
Ejemplo n.º 15
0
 /**
  * This method tests that an item is removed in the collection.
  *
  * @dataProvider dataRemoveKey
  */
 public function testRemoveKey(array $provided, array $expected)
 {
     //$this->markTestIncomplete();
     $entries = array(ITuple\Type::box2(IString\Type::box('key0'), IInt32\Type::zero()), ITuple\Type::box2(IString\Type::box('key1'), IInt32\Type::one()), ITuple\Type::box2(IString\Type::box('key2'), IInt32\Type::box(2)));
     $p0 = IHashMap\Type::make($entries);
     foreach ($provided as $key) {
         $p0->removeKey($key);
     }
     $p1 = $p0->size()->unbox();
     $e1 = $expected[0];
     $this->assertSame($e1, $p1);
 }
Ejemplo n.º 16
0
 /**
  * This method returns the line at which the exception was thrown.
  *
  * @access public
  * @static
  * @param Throwable\Runtime\Exception $x                    the exception to be processed
  * @return integer                                          the source line
  */
 public static function getLine(Throwable\Runtime\Exception $x)
 {
     return IInt32\Type::box($x->__getLine());
 }
Ejemplo n.º 17
0
 /**
  * This method tests the "split" method.
  *
  * @dataProvider data_split
  */
 public function test_split(array $provided, array $expected)
 {
     if (is_array($provided[1])) {
         $p0 = IRegex\Module::split(IRegex\Type::box($provided[0]), ITuple\Type::box2(IString\Type::box($provided[1][0]), IInt32\Type::box($provided[1][1])));
     } else {
         $p0 = IRegex\Module::split(IRegex\Type::box($provided[0]), IString\Type::box($provided[1]));
     }
     $e0 = $expected[0];
     $this->assertInstanceOf('\\Saber\\Data\\IArrayList\\Type', $p0);
     $this->assertSame($e0, $p0->unbox(1));
 }
Ejemplo n.º 18
0
 /**
  * This method tests the "item" related methods.
  */
 public function test_items()
 {
     $p0 = ITuple\Type::box2(IInt32\Type::zero(), IInt32\Type::one(), IInt32\Type::box(2));
     $this->assertSame(0, $p0->item(IInt32\Type::zero())->unbox());
     $this->assertSame(1, $p0->item(IInt32\Type::one())->unbox());
     $this->assertSame(2, $p0->item(IInt32\Type::box(2))->unbox());
     $this->assertSame(0, $p0->first()->unbox());
     $this->assertSame(1, $p0->second()->unbox());
 }
Ejemplo n.º 19
0
 /**
  * This method tests the "item" related methods.
  */
 public function test_items()
 {
     $p0 = ILinkedList\Type::box2(IInt32\Type::zero(), IInt32\Type::one(), IInt32\Type::box(2));
     $this->assertSame(0, $p0->item(IInt32\Type::zero())->unbox());
     $this->assertSame(1, $p0->item(IInt32\Type::one())->unbox());
     $this->assertSame(2, $p0->item(IInt32\Type::box(2))->unbox());
     $this->assertSame(0, $p0->head()->unbox());
     $p1 = $p0->tail();
     $this->assertInstanceOf('\\Saber\\Data\\ILinkedList\\Type', $p1);
     $this->assertSame(array(1, 2), $p1->unbox(1));
 }
Ejemplo n.º 20
0
 /**
  * This method returns the value as an IInt32. Note: Using this method may result in
  * lost of precision.
  *
  * @access public
  * @static
  * @param IChar\Type $x                                     the object to be converted
  * @return IInt32\Type                                      the value as an IInt32
  */
 public static function toInt32(IChar\Type $x) : IInt32\Type
 {
     return IInt32\Type::box(ord($x->unbox()));
 }