From: Michael M Slusarz Date: Tue, 10 Aug 2010 23:09:26 +0000 (-0600) Subject: Add some uniqueness tests for random id generation X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=041ae029b224d928de8cc039edff0dab193a95fb;p=horde.git Add some uniqueness tests for random id generation --- diff --git a/framework/Support/test/Horde/Support/RandomidTest.php b/framework/Support/test/Horde/Support/RandomidTest.php index 26be46ae2..e710b83c9 100644 --- a/framework/Support/test/Horde/Support/RandomidTest.php +++ b/framework/Support/test/Horde/Support/RandomidTest.php @@ -23,4 +23,21 @@ class Horde_Support_RandomidTest extends PHPUnit_Framework_TestCase $this->assertEquals(16, strlen($rid)); } + public function testRandomidDuplicates() + { + $values = array(); + $cnt = 0; + + for ($i = 0; $i < 10000; ++$i) { + $id = strval(new Horde_Support_Randomid()); + if (isset($values[$id])) { + $cnt++; + } else { + $values[$id] = 1; + } + } + + $this->assertEquals(0, $cnt); + } + } diff --git a/framework/Support/test/Horde/Support/UuidTest.php b/framework/Support/test/Horde/Support/UuidTest.php index eaf7a4fbb..5b3d7b05e 100644 --- a/framework/Support/test/Horde/Support/UuidTest.php +++ b/framework/Support/test/Horde/Support/UuidTest.php @@ -22,8 +22,25 @@ class Horde_Support_UuidTest extends PHPUnit_Framework_TestCase */ public function testUuidLength() { - $uuid = (string)new Horde_Support_Uuid; + $uuid = strval(new Horde_Support_Uuid()); $this->assertEquals(36, strlen($uuid)); } + public function testUuidDuplicates() + { + $values = array(); + $cnt = 0; + + for ($i = 0; $i < 10000; ++$i) { + $id = strval(new Horde_Support_Uuid()); + if (isset($values[$id])) { + $cnt++; + } else { + $values[$id] = 1; + } + } + + $this->assertEquals(0, $cnt); + } + }