예제 #1
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));
     }
 }
예제 #2
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;
 }