예제 #1
0
	
	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU Affero General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.
	
	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU Affero General Public License for more details.
	
	You should have received a copy of the GNU Affero General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
WootChar::$CB = new WootChar(WootID::$IDB, '[', false, 0);
WootChar::$CE = new WootChar(WootID::$IDE, ']', false, 0);
class WootChar
{
    /** @var WootID id */
    public $id;
    /** @var string value */
    public $value;
    /** @var boolean visible */
    public $visible;
    /** @var int degree */
    public $degree;
    public static $CB;
    public static $CE;
    public function __construct($id, $value, $visible, $degree)
    {
        $this->id = $id;
예제 #2
0
파일: WootTest.php 프로젝트: raisanen/tlon
 public function testWootChar()
 {
     list($val, $vis, $deg) = array(self::$CHAR_VALUE, self::$CHAR_VISIBLE, self::$CHAR_DEGREE);
     $id = new WootID(self::$SITE_ID, self::$CHAR_ID);
     $char = new WootChar($id, $val, $vis, $deg);
     $this->assertEquals($val, $char->getValue());
     $this->assertEquals($vis, $char->visible);
     $this->assertEquals($deg, $char->degree);
     $this->assertTrue($id->equals($char->getID()));
     for ($i = 0; $i < self::$NUM_RANDOM_TESTS; $i++) {
         do {
             $randDeg = rand(0, 255);
         } while ($randDeg == $deg);
         do {
             $randSiteID = rand(0, 255);
         } while ($randSiteID == self::$SITE_ID);
         $randCharID = rand(0, 255);
         $randChar = new WootChar(new WootID($randSiteID, $randCharID), $val, $vis, $randDeg);
         $this->assertFalse($randChar->equals($char));
         $this->assertFalse($char->equals($randChar));
         if ($randSiteID < self::$SITE_ID) {
             $this->assertEquals(-1, $randChar->compareTo($char));
             $this->assertEquals(1, $char->compareTo($randChar));
             $this->assertTrue($randChar->precedes($char));
             $this->assertFalse($char->precedes($randChar));
         } else {
             if ($randSiteID > self::$SITE_ID) {
                 $this->assertEquals(1, $randChar->compareTo($char));
                 $this->assertEquals(-1, $char->compareTo($randChar));
                 $this->assertFalse($randChar->precedes($char));
                 $this->assertTrue($char->precedes($randChar));
             }
         }
         $this->assertEquals(-1, $randChar->compareTo(WootChar::$CE));
         $this->assertEquals(1, $randChar->compareTo(WootChar::$CB));
         $this->assertTrue($randChar->precedes(WootChar::$CE));
         $this->assertFalse($randChar->precedes(WootChar::$CB));
         $this->assertEquals(-1, WootChar::$CB->compareTo($randChar));
         $this->assertEquals(1, WootChar::$CE->compareTo($randChar));
         $this->assertTrue(WootChar::$CB->precedes($randChar));
         $this->assertFalse(WootChar::$CE->precedes($randChar));
     }
 }
예제 #3
0
 /**
  * @param WootChar $c
  * @return int The index of $c within $wootChars
  */
 public function pos($c)
 {
     if ($c == null) {
         return -1;
     }
     for ($i = 0; $i < $this->length(); $i++) {
         if ($c->equals($this->wootChars[$i])) {
             return $i;
         }
     }
     return -1;
 }