예제 #1
0
 /**
  * This method tests the "nvl" method.
  */
 public function test_nvl()
 {
     $x = ITrit\Type::positive();
     $y = ITrit\Type::zero();
     $z = ITrit\Module::nvl($x, $y);
     $this->assertInstanceOf('\\Saber\\Data\\ITrit\\Type', $z);
     $this->assertSame(1, $z->unbox());
     $z = ITrit\Module::nvl(null, $x);
     $this->assertInstanceOf('\\Saber\\Data\\ITrit\\Type', $z);
     $this->assertSame(1, $z->unbox());
     $z = ITrit\Module::nvl(null, null);
     $this->assertInstanceOf('\\Saber\\Data\\ITrit\\Type', $z);
     $this->assertSame(0, $z->unbox());
 }
예제 #2
0
 /**
  * This method compares the operands for order.
  *
  * @access public
  * @static
  * @param ITrit\Type $x                                     the left operand
  * @param ITrit\Type $y                                     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(ITrit\Type $x, ITrit\Type $y) : ITrit\Type
 {
     $__x = $x->unbox();
     $__y = $y->unbox();
     if ($__x < $__y) {
         return ITrit\Type::negative();
     } else {
         if ($__x == $__y) {
             return ITrit\Type::zero();
         } else {
             // ($__x > $__y)
             return ITrit\Type::positive();
         }
     }
 }
예제 #3
0
 /**
  * This method compares the specified object with the current object for order.
  *
  * @access public
  * @static
  * @param IOption\Type $xs                                  the left operand
  * @param IOption\Type $ys                                  the object to be compared
  * @return ITrit\Type                                       whether the current object is less than,
  *                                                          equal to, or greater than the specified
  *                                                          object
  */
 public static function compare(IOption\Type $xs, IOption\Type $ys) : ITrit\Type
 {
     $x = $xs->__isDefined();
     $y = $ys->__isDefined();
     if (!$x && $y) {
         return ITrit\Type::negative();
     }
     if (!$x && !$y) {
         return ITrit\Type::zero();
     }
     if ($x && !$y) {
         return ITrit\Type::positive();
     }
     $x = $xs->item();
     $y = $ys->item();
     if ($x === null && $y !== null) {
         return ITrit\Type::negative();
     }
     if ($x === null && $y === null) {
         return ITrit\Type::zero();
     }
     if ($x !== null && $y === null) {
         return ITrit\Type::positive();
     }
     if ($x instanceof Core\Comparable\Type) {
         return call_user_func_array(array($x, 'compare'), array($y));
     }
     return IString\Module::compare(Core\Module::hashCode($x), Core\Module::hashCode($y));
 }
예제 #4
0
 /**
  * This method compares the operands for order.
  *
  * @access public
  * @static
  * @param Throwable\Runtime\Exception $x                    the left operand
  * @param Throwable\Runtime\Exception $y                    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(Throwable\Runtime\Exception $x, Throwable\Runtime\Exception $y)
 {
     $x = $x->__getCode();
     $y = $y->__getCode();
     if ($x < $y) {
         return ITrit\Type::negative();
     } else {
         if ($x == $y) {
             return ITrit\Type::zero();
         } else {
             // ($x > $y)
             return ITrit\Type::positive();
         }
     }
 }
예제 #5
0
 /**
  * This method tests the "singletons" methods.
  */
 public function test_singletons()
 {
     $p0 = ITrit\Type::negative();
     $e0 = ITrit\Type::negative();
     $this->assertInstanceOf('\\Saber\\Data\\ITrit\\Type', $p0);
     $this->assertSame($e0->__hashCode(), $p0->__hashCode());
     $p1 = $p0->unbox();
     $e1 = -1;
     $this->assertInternalType('integer', $p1);
     $this->assertSame($e1, $p1);
     $p2 = ITrit\Type::zero();
     $e2 = ITrit\Type::zero();
     $this->assertInstanceOf('\\Saber\\Data\\ITrit\\Type', $p2);
     $this->assertSame($e2->__hashCode(), $p2->__hashCode());
     $p3 = $p2->unbox();
     $e3 = 0;
     $this->assertInternalType('integer', $p3);
     $this->assertSame($e3, $p3);
     $p4 = ITrit\Type::positive();
     $e4 = ITrit\Type::positive();
     $this->assertInstanceOf('\\Saber\\Data\\ITrit\\Type', $p4);
     $this->assertSame($e4->__hashCode(), $p4->__hashCode());
     $p5 = $p4->unbox();
     $e5 = 1;
     $this->assertInternalType('integer', $p5);
     $this->assertSame($e5, $p5);
 }
예제 #6
0
 /**
  * This method compares the specified object with the current object for order.
  *
  * @access public
  * @static
  * @param IHashMap\Type $xs                                 the left operand
  * @param IHashMap\Type $ys                                 the object to be compared
  * @return ITrit\Type                                       whether the current object is less than,
  *                                                          equal to, or greater than the specified
  *                                                          object
  */
 public static function compare(IHashMap\Type $xs, IHashMap\Type $ys) : ITrit\Type
 {
     $x_length = $xs->__size();
     $y_length = $ys->__size();
     if ($x_length == $y_length) {
         $xi = IHashMap\Module::iterator($xs);
         foreach ($xi as $k => $v) {
             if (!$ys->__hasKey($k) || !$ys->item($k)->__eq($v)) {
                 return ITrit\Type::make(strcmp((string) serialize($xs), (string) serialize($ys)));
                 // order is not "stable"
             }
         }
         return ITrit\Type::zero();
     } else {
         if ($x_length < $y_length) {
             return ITrit\Type::negative();
         } else {
             // ($x_length > $y_length)
             return ITrit\Type::positive();
         }
     }
 }