/** * This method tests the "nvl" method. */ public function test_nvl() { $x = IInteger\Type::one(); $y = IInteger\Type::zero(); $z = IInteger\Module::nvl($x, $y); $this->assertInstanceOf('\\Saber\\Data\\IInteger\\Type', $z); $this->assertSame('1', $z->unbox()); $z = IInteger\Module::nvl(null, $x); $this->assertInstanceOf('\\Saber\\Data\\IInteger\\Type', $z); $this->assertSame('1', $z->unbox()); $z = IInteger\Module::nvl(null, null); $this->assertInstanceOf('\\Saber\\Data\\IInteger\\Type', $z); $this->assertSame('0', $z->unbox()); }
/** * This method returns a list of all numbers for the specified sequence. * * @access public * @static * @param IInteger\Type $x where to start * @param Core\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(IInteger\Type $x, Core\Type $y) : IArrayList\Type { $buffer = array(); if ($y instanceof ITuple\Type) { $s = IInteger\Module::subtract($y->first(), $x); $n = $y->second(); } else { // ($y instanceof IInteger\Type) $s = IInteger\Type::one(); $n = $y; } if (IInteger\Module::isNegative($s)->unbox()) { for ($i = $x; IInteger\Module::ge($i, $n)->unbox(); $i = IInteger\Module::add($i, $s)) { $buffer[] = $i; } } else { for ($i = $x; IInteger\Module::le($i, $n)->unbox(); $i = IInteger\Module::add($i, $s)) { $buffer[] = $i; } } return IArrayList\Type::box($buffer); }
/** * This method tests the "singletons" methods. */ public function test_singletons() { $p0 = IInteger\Type::negative(); $e0 = IInteger\Type::negative(); $this->assertInstanceOf('\\Saber\\Data\\IInteger\\Type', $p0); $this->assertSame($e0->__hashCode(), $p0->__hashCode()); $p1 = $p0->unbox(); $e1 = '-1'; $this->assertInternalType('string', $p1); $this->assertSame($e1, $p1); $p2 = IInteger\Type::zero(); $e2 = IInteger\Type::zero(); $this->assertInstanceOf('\\Saber\\Data\\IInteger\\Type', $p2); $this->assertSame($e2->__hashCode(), $p2->__hashCode()); $p3 = $p2->unbox(); $e3 = '0'; $this->assertInternalType('string', $p3); $this->assertSame($e3, $p3); $p4 = IInteger\Type::one(); $e4 = IInteger\Type::one(); $this->assertInstanceOf('\\Saber\\Data\\IInteger\\Type', $p4); $this->assertSame($e4->__hashCode(), $p4->__hashCode()); $p5 = $p4->unbox(); $e5 = '1'; $this->assertInternalType('string', $p5); $this->assertSame($e5, $p5); }