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)); } }
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/>. */ /** * WootID represents the unique ID of a WootChar, and consists of two * integers: siteID and charID. SiteID is given to a client by the server, * and charID is constructed by the client via a counter representing * the number of inserts it's done in a given WootDocument. */ WootID::$IDB = new WootID(-1, -1); WootID::$IDE = new WootID(-2, -2); class WootID { /** @var int siteID */ public $siteID; /** @var int charID */ public $charID; public static $IDB; public static $IDE; public function __construct($siteID, $charID) { $this->siteID = $siteID; $this->charID = $charID; } public function getSiteID() {