forked from marekweb/opaque-id
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.php
40 lines (29 loc) · 862 Bytes
/
tests.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
<?php
/**
* Basic test for OpaqueEncoder.
*
* Checks round-trip encoding with random values. Uses assert statements, so
* if no errors show up, the test was successful.
*/
require_once 'OpaqueEncoder.php';
print "Starting tests... ";
$key = mt_rand();
$encoder = new OpaqueEncoder($key, OpaqueEncoder::ENCODING_INT);
for ($i = 0; $i < 800; $i++) {
$n = mt_rand();
$encoded = $encoder->encode($n);
assert($n == $encoder->decode($encoded));
}
$encoder = new OpaqueEncoder($key, OpaqueEncoder::ENCODING_HEX);
for ($i = 0; $i < 800; $i++) {
$n = mt_rand();
$encoded = $encoder->encode($n);
assert($n == $encoder->decode($encoded));
}
$encoder = new OpaqueEncoder($key, OpaqueEncoder::ENCODING_BASE64);
for ($i = 0; $i < 800; $i++) {
$n = mt_rand();
$encoded = $encoder->encode($n);
assert($n == $encoder->decode($encoded));
}
print "Done.";