/** * This method tests the "some" method. */ public function test_some() { $p0 = IOption\Type::some(IInt32\Type::zero()); $e0 = IOption\Type::some(IInt32\Type::one()); $this->assertInstanceOf('\\Saber\\Data\\IOption\\Type', $p0); $this->assertNotSame($e0->__hashCode(), $p0->__hashCode()); }
/** * This method tests the "right" method. */ public function test_right() { $p0 = IEither\Type::right(IInt32\Type::zero()); $e0 = IEither\Type::right(IInt32\Type::one()); $this->assertInstanceOf('\\Saber\\Data\\IEither\\Right\\Type', $p0); $this->assertNotSame($e0->__hashCode(), $p0->__hashCode()); }
/** * The method intersperses the specified object between each item in the string. * * @access public * @static * @param IString\Type $xs the left operand * @param Core\Type $y the object to be interspersed * @return IString\Type the string * @throws Throwable\InvalidArgument\Exception indicates an invalid argument */ public static function intersperse(IString\Type $xs, Core\Type $y) : IString\Type { $buffer = ''; $length = $xs->length(); if ($length->unbox() > 0) { $buffer .= IString\Module::item($xs, IInt32\Type::zero())->unbox(); for ($i = IInt32\Type::one(); IInt32\Module::lt($i, $length)->unbox(); $i = IInt32\Module::increment($i)) { $buffer .= $y->__toString(); $buffer .= $xs->__item($i); } } return IString\Type::box($buffer); }
/** * 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()))); }
/** * 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)); }
/** * 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()); }
/** * This method tests the "nvl" method. */ public function test_nvl() { $x = IInt32\Type::one(); $y = IInt32\Type::zero(); $z = IInt32\Module::nvl($x, $y); $this->assertInstanceOf('\\Saber\\Data\\IInt32\\Type', $z); $this->assertSame(1, $z->unbox()); $z = IInt32\Module::nvl(null, $x); $this->assertInstanceOf('\\Saber\\Data\\IInt32\\Type', $z); $this->assertSame(1, $z->unbox()); $z = IInt32\Module::nvl(null, null); $this->assertInstanceOf('\\Saber\\Data\\IInt32\\Type', $z); $this->assertSame(0, $z->unbox()); }
/** * This method returns a random number with the range of x and y. * * @access public * @static * @param IInteger\Type $x the min operand * @param IInt32\Type $y the max operand * @return IInteger\Type the result */ public static function random(IInteger\Type $x = null, IInt32\Type $y = null) : IInteger\Type { return IInteger\Type::box(gmp_strval(gmp_random(IInt32\Module::nvl($y, IInt32\Type::one())->unbox()))); }
/** * This method tests the "singletons" methods. */ public function test_singletons() { $p0 = IInt32\Type::negative(); $e0 = IInt32\Type::negative(); $this->assertInstanceOf('\\Saber\\Data\\IInt32\\Type', $p0); $this->assertSame($e0->__hashCode(), $p0->__hashCode()); $p1 = $p0->unbox(); $e1 = -1; $this->assertInternalType('integer', $p1); $this->assertSame($e1, $p1); $p2 = IInt32\Type::zero(); $e2 = IInt32\Type::zero(); $this->assertInstanceOf('\\Saber\\Data\\IInt32\\Type', $p2); $this->assertSame($e2->__hashCode(), $p2->__hashCode()); $p3 = $p2->unbox(); $e3 = 0; $this->assertInternalType('integer', $p3); $this->assertSame($e3, $p3); $p4 = IInt32\Type::one(); $e4 = IInt32\Type::one(); $this->assertInstanceOf('\\Saber\\Data\\IInt32\\Type', $p4); $this->assertSame($e4->__hashCode(), $p4->__hashCode()); $p5 = $p4->unbox(); $e5 = 1; $this->assertInternalType('integer', $p5); $this->assertSame($e5, $p5); }
/** * 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()); }
/** * This method provides the data for testing the boxing of a value. * * @return array */ public function data_box() { $data = array(array(array(new Throwable\InvalidArgument\Exception('', array(), IInt32\Type::zero())), array(0)), array(array(new Throwable\InvalidArgument\Exception('', array(), null)), array(0)), array(array(new Throwable\InvalidArgument\Exception('', array(), IInt32\Type::one())), array(1))); return $data; }
/** * 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; }
/** * 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(ITuple\Type::box2(IString\Type::box('key0'), IInt32\Type::zero())), array(1)), array(array(ITuple\Type::box2(IString\Type::box('key0'), IInt32\Type::zero()), ITuple\Type::box2(IString\Type::box('key1'), IInt32\Type::one())), array(2))); return $data; }
/** * This method returns whether the ratio is a whole number. * * @access public * @static * @param IRatio\Type $x the ratio to be evaluated * @return IBool\Type whether the ratio is a whole * number */ public static function isInteger(IRatio\Type $x) : IBool\Type { return IBool\Module::or_(IInt32\Module::eq($x->numerator(), IInt32\Type::zero()), IInt32\Module::eq($x->denominator(), IInt32\Type::one())); }
/** * This method returns an object with a "0" value. * * @access public * @static * @return IRatio\Type the object */ public static function zero() { if (!isset(static::$singletons[0])) { static::$singletons[0] = new IRatio\Type(IInt32\Type::zero(), IInt32\Type::one()); } return static::$singletons[0]; }
/** * This method provides the data for testing the making of a boxed value. * * @return array */ public function data_singleton() { $data = array(array(array(IRatio\Type::one()), array(IInt32\Type::one(), IInt32\Type::one())), array(array(IRatio\Type::zero()), array(IInt32\Type::zero(), IInt32\Type::one())), array(array(IRatio\Type::negative()), array(IInt32\Type::negative(), IInt32\Type::one()))); return $data; }
/** * The method intersperses the specified object between each item in the list. * * @access public * @static * @param IArrayList\Type $xs the left operand * @param Core\Type $y the object to be interspersed * @return IArrayList\Type the list * @throws Throwable\InvalidArgument\Exception indicates an invalid argument */ public static function intersperse(IArrayList\Type $xs, Core\Type $y) : IArrayList\Type { $buffer = array(); $length = $xs->length(); if ($length > 0) { $buffer[] = $xs->item(IInt32\Type::zero()); for ($i = IInt32\Type::one(); IInt32\Module::lt($i, $length)->unbox(); $i = IInt32\Module::increment($i)) { $buffer[] = $y; $buffer[] = $xs->item($i); } } return IArrayList\Type::box($buffer); }