Skip to content

Commit

Permalink
Better way of checking for duplicates
Browse files Browse the repository at this point in the history
  • Loading branch information
slusarz committed Jan 13, 2015
1 parent dd2beb7 commit c9b2e58
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 24 deletions.
10 changes: 2 additions & 8 deletions framework/Support/test/Horde/Support/GuidTest.php
Expand Up @@ -26,18 +26,12 @@ public function testFormat()
public function testDuplicates()
{
$values = array();
$cnt = 0;

for ($i = 0; $i < 10000; ++$i) {
$id = strval(new Horde_Support_Guid());
if (isset($values[$id])) {
$cnt++;
} else {
$values[$id] = 1;
}
$this->assertArrayNotHasKey($id, $values);
$values[$id] = 1;
}

$this->assertEquals(0, $cnt);
}

public function testOptions()
Expand Down
10 changes: 2 additions & 8 deletions framework/Support/test/Horde/Support/RandomidTest.php
Expand Up @@ -24,17 +24,11 @@ public function testLength()
public function testDuplicates()
{
$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->assertArrayNotHasKey($id, $values);
$values[$id] = 1;
}

$this->assertEquals(0, $cnt);
}
}
10 changes: 2 additions & 8 deletions framework/Support/test/Horde/Support/UuidTest.php
Expand Up @@ -24,17 +24,11 @@ public function testLength()
public function testDuplicates()
{
$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->assertArrayNotHasKey($id, $values);
$values[$id] = 1;
}

$this->assertEquals(0, $cnt);
}
}

0 comments on commit c9b2e58

Please sign in to comment.