forked from phacility/phabricator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhabricatorHashTestCase.php
41 lines (34 loc) · 992 Bytes
/
PhabricatorHashTestCase.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
final class PhabricatorHashTestCase extends PhabricatorTestCase {
public function testHashForIndex() {
$map = array(
'dog' => 'Aliif7Qjd5ct',
'cat' => 'toudDsue3Uv8',
'rat' => 'RswaKgTjqOuj',
'bat' => 'rAkJKyX4YdYm',
);
foreach ($map as $input => $expect) {
$this->assertEqual(
$expect,
PhabricatorHash::digestForIndex($input),
"Input: {$input}");
}
// Test that the encoding produces 6 bits of entropy per byte.
$entropy = array(
'dog', 'cat', 'rat', 'bat', 'dig', 'fig', 'cot',
'cut', 'fog', 'rig', 'rug', 'dug', 'mat', 'pat',
'eat', 'tar', 'pot',
);
$seen = array();
foreach ($entropy as $input) {
$chars = preg_split('//', PhabricatorHash::digestForIndex($input));
foreach ($chars as $char) {
$seen[$char] = true;
}
}
$this->assertEqual(
(1 << 6),
count($seen),
"Distinct characters in hash of: {$input}");
}
}