/** * This method tests the "min" method. * * @dataProvider data_min */ public function test_min(array $provided, array $expected) { $p0 = IInt32\Module::min(IInt32\Type::box($provided[0]), IInt32\Type::box($provided[1])); $e0 = $expected[0]; $this->assertInstanceOf('\\Saber\\Data\\IInt32\\Type', $p0); $this->assertSame($e0, $p0->unbox()); }
/** * This method returns the first "n" items in the string. * * @access public * @static * @param IString\Type $xs the left operand * @param IInt32\Type $n the number of items to take * @return IString\Type the string */ public static function take(IString\Type $xs, IInt32\Type $n) : IString\Type { $buffer = ''; $length = IInt32\Module::min($n, $xs->length()); for ($i = IInt32\Type::zero(); IInt32\Module::lt($i, $length)->unbox(); $i = IInt32\Module::increment($i)) { $buffer .= $xs->__item($i); } return IString\Type::box($buffer); }
/** * 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()); }