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)); }
/** * 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'); } } }