From 041ae029b224d928de8cc039edff0dab193a95fb Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Tue, 10 Aug 2010 17:09:26 -0600 Subject: [PATCH] Add some uniqueness tests for random id generation --- framework/Support/test/Horde/Support/RandomidTest.php | 17 +++++++++++++++++ framework/Support/test/Horde/Support/UuidTest.php | 19 ++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) 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); + } + } -- 2.11.0