/** * 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()); } }
/** * This method tests the "iterator" method. */ public function test_iterator() { $p0 = IOption\Type::some(IInt32\Type::zero()); $e0 = array(0); $this->assertInstanceOf('\\Saber\\Data\\IOption\\Some\\Type', $p0); $this->assertSame(count($e0), $p0->__size()); $p1 = IOption\Module::iterator($p0); $e1 = 0; $this->assertInstanceOf('\\Saber\\Data\\IOption\\Iterator', $p1); foreach ($p1 as $i => $item) { $this->assertInstanceOf('\\Saber\\Data\\IInt32\\Type', $i); $this->assertSame($e1, $i->unbox()); $this->assertInstanceOf('\\Saber\\Core\\Type', $item); $this->assertSame($e0[$e1], $item->unbox()); $e1++; } }
/** * This method tests a set of choices. */ public function testChoice() { //$this->markTestIncomplete(); $p0 = IInt32\Type::make(0); $e0 = 0; $p1 = IInt32\Type::make(1); $e1 = 1; Control\Type::choice($p0)->when($p0, function (IInt32\Type $x) use($e0) { $this->assertSame($e0, $x->unbox()); })->otherwise(function (IInt32\Type $x) use($e1) { $this->assertSame($e1, $x->unbox()); })->end(); Control\Type::choice($p0)->when($p1, function (IInt32\Type $x) use($e1) { $this->assertSame($e1, $x->unbox()); })->when($p0, function (IInt32\Type $x) use($e0) { $this->assertSame($e0, $x->unbox()); })->end(); Control\Type::choice($p0)->when($p1, function (IInt32\Type $x) use($e1) { $this->assertSame($e1, $x->unbox()); })->otherwise(function (IInt32\Type $x) use($e0) { $this->assertSame($e0, $x->unbox()); })->end(); }
/** * This method evaluates whether the operand is an odd number. * * @access public * @static * @param IInt32\Type $x the object to be evaluated * @return IBool\Type whether the operand is an odd * number */ public static function isOdd(IInt32\Type $x) : IBool\Type { return IBool\Type::box($x->unbox() % 2 != 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()); }
/** * This method compares the operands for order. * * @access public * @static * @param ITuple\Type $xs the left operand * @param ITuple\Type $ys the right operand * @return ITrit\Type the order as to whether the left * operand is less than, equals to, * or greater than the right operand */ public static function compare(ITuple\Type $xs, ITuple\Type $ys) : ITrit\Type { $xsl = $xs->length(); $ysl = $ys->length(); $length = IInt32\Module::min($xsl, $ysl); for ($i = IInt32\Type::zero(); IInt32\Module::lt($i, $length)->unbox(); $i = IInt32\Module::increment($i)) { $r = $xs->item($i)->compare($ys->item($i)); if ($r->unbox() != 0) { return $r; } } return ITrit\Type::box($xsl->unbox() <=> $ysl->unbox()); }
/** * This method provides the data for testing that a value is converted to a string. * * @return array */ public function data_toString() { $data = array(array(array(new Throwable\InvalidArgument\Exception('Message', array(), IInt32\Type::zero())), array('Saber\\Throwable\\InvalidArgument\\Exception [ 0 ]: Message ~ '))); return $data; }
/** * This method provides the data for testing that a value is converted to a string. * * @return array */ public function data_toString() { $data = array(array(array('Message', array(), IInt32\Type::zero()), array('Saber\\Throwable\\EmptyCollection\\Exception [ 0 ]: Message ~ '))); return $data; }
/** * 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)); }
/** * 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()); }
/** * This method rewinds the iterator. * * @access public * @final */ public final function rewind() { $this->ys = $this->xs; $this->i = IInt32\Type::zero(); }
/** * 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 returns a pair of hash maps: those items that satisfy the predicate and * those items that do not satisfy the predicate. * * @access public * @static * @param IHashMap\Type $xs the hash map to be partitioned * @param callable $predicate the predicate function to be used * @return ITuple\Type the results */ public static function partition(IHashMap\Type $xs, callable $predicate) : ITuple\Type { $passed = IHashMap\Type::empty_(); $failed = IHashMap\Type::empty_(); $xi = IHashMap\Module::iterator($xs); $i = IInt32\Type::zero(); foreach ($xi as $k => $v) { $entry = ITuple\Type::box2($k, $v); if ($predicate($entry, $i)->unbox()) { $passed->putEntry($entry->first(), $entry->second()); } else { $failed->putEntry($entry->first(), $entry->second()); } } return ITuple\Type::box2($passed, $failed); }
/** * 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()); }
/** * This method applies each item in this either to the subroutine function. * * @access public * @final * @param callable $subroutine the subroutine function to be used * @return IEither\Type the either */ public final function map(callable $subroutine) : IEither\Type { return $this->either->__isLeft() ? IEither\Type::left($subroutine($this->either->item(), IInt32\Type::zero())) : IEither\Type::right($this->either->projectRight()->item()); }
/** * 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 returns the collection as a linked list. * * @access public * @static * @param IString\Type $xs the operand * @return ILinkedList\Type the collection as a linked list */ public static function toLinkedList(IString\Type $xs) : ILinkedList\Type { $length = $xs->length(); $zs = ILinkedList\Type::nil(); for ($i = IInt32\Module::decrement($length); IInt32\Module::ge($i, IInt32\Type::zero())->unbox(); $i = IInt32\Module::decrement($i)) { $zs = ILinkedList\Type::cons($xs->item($i), $zs); } return $zs; }
/** * 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 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()); }
/** * 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 "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()); }
/** * 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)); }
/** * 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()); }
/** * This method returns the value as an IInt32. Note: Using this method may result in * lost of precision. * * @access public * @static * @param ITrit\Type $x the object to be converted * @return IInt32\Type the value as an IInt32 */ public static function toInt32(ITrit\Type $x) : IInt32\Type { return IInt32\Type::make($x->unbox()); }
/** * This method returns the first object in the collection that passes the truthy test, if any. * * @access public * @static * @param IOption\Type $xs the left operand * @param callable $predicate the predicate function to be used * @return IOption\Type an option containing the first object * satisfying the predicate, if any */ public static function find(IOption\Type $xs, callable $predicate) : IOption\Type { if (IBool\Module::and_($xs->isDefined(), $predicate($xs->item(), IInt32\Type::zero()))->unbox()) { return $xs; } return IOption\Type::none(); }
/** * 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()); }
/** * This method returns whether the iterator is still valid. * * @access public * @final * @return bool whether there are more objects */ public final function valid() : bool { return $this->i->unbox() < $this->xs->__size(); }
/** * This method returns the length of this linked list. * * @access public * @final * @return IInt32\Type the length of this linked list */ public final function length() : IInt32\Type { $c = IInt32\Type::zero(); for ($zs = $this; !$zs->__isEmpty(); $zs = $zs->tail()) { $c = IInt32\Module::increment($c); } return $c; }
/** * 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; }
/** * 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; }