Add some uniqueness tests for random id generation
authorMichael M Slusarz <slusarz@curecanti.org>
Tue, 10 Aug 2010 23:09:26 +0000 (17:09 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Tue, 10 Aug 2010 23:09:26 +0000 (17:09 -0600)
framework/Support/test/Horde/Support/RandomidTest.php
framework/Support/test/Horde/Support/UuidTest.php

index 26be46a..e710b83 100644 (file)
@@ -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);
+    }
+
 }
index eaf7a4f..5b3d7b0 100644 (file)
@@ -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);
+    }
+
 }