예제 #1
0
 public function testCompare()
 {
     $l = '387456384576';
     $r = '879634347653';
     $this->assertEquals(Number::COMPARISON_LESS_THAN, Number::compare($l, $r));
     $l = '483756837645';
     $r = '483756837645';
     $this->assertEquals(Number::COMPARISON_EQUAL, Number::compare($l, $r));
     $l = '38745834587384573084';
     $r = '17346587934543534';
     $this->assertEquals(Number::COMPARISON_GREATER_THAN, Number::compare($l, $r));
 }
예제 #2
0
파일: Enum.php 프로젝트: dazarobbo/cola
 /**
  * Checks whether this enum's interval value matches another
  * @param static $obj
  * @return int
  * @throws \RuntimeException
  */
 public function compareTo($obj)
 {
     if (!\is_a($obj, \get_called_class())) {
         throw new \RuntimeException('$obj is not a comparable instance');
     }
     if (\is_int($this->_Value) && \is_int($obj->_Value)) {
         return Number::compare($this->_Value, $obj->_Value);
     } else {
         if (\is_string($this->_Value) && \is_string($obj->_Value)) {
             return \strcmp($this->_Value, $obj->_Value);
         } else {
             throw new \RuntimeException('Incomparable types');
         }
     }
 }