19 $id = call_user_func( [
'UIDGenerator', $method ] );
20 $this->assertEquals(
true, ctype_digit( $id ),
"UID made of digit characters" );
21 $this->assertLessThanOrEqual( $digitlen, strlen( $id ),
22 "UID has the right number of digits" );
23 $this->assertLessThanOrEqual( $bits, strlen(
Wikimedia\base_convert( $id, 10, 2 ) ),
24 "UID has the right number of bits" );
27 for ( $i = 0; $i < 300; $i++ ) {
28 $ids[] = call_user_func( [
'UIDGenerator', $method ] );
31 $lastId = array_shift( $ids );
33 $this->assertSame( array_unique( $ids ), $ids,
"All generated IDs are unique." );
35 foreach ( $ids
as $id ) {
38 $id_bin = Wikimedia\base_convert( $id, 10, 2, $bits );
39 $lastId_bin = Wikimedia\base_convert( $lastId, 10, 2, $bits );
41 $timestamp_bin = substr( $id_bin, 0, $tbits );
42 $last_timestamp_bin = substr( $lastId_bin, 0, $tbits );
44 $this->assertGreaterThanOrEqual(
47 "timestamp ($timestamp_bin) of current ID ($id_bin) >= timestamp ($last_timestamp_bin) " .
48 "of prior one ($lastId_bin)" );
50 $hostbits_bin = substr( $id_bin, -$hostbits );
51 $last_hostbits_bin = substr( $lastId_bin, -$hostbits );
57 "Host ID ($hostbits_bin) of current ID ($id_bin) is same as host ID ($last_hostbits_bin) " .
58 "of prior one ($lastId_bin)." );
71 [
'newTimestampedUID128', 39, 128, 46, 48 ],
72 [
'newTimestampedUID128', 39, 128, 46, 48 ],
73 [
'newTimestampedUID88', 27, 88, 46, 32 ],
82 for ( $i = 0; $i < 100; $i++ ) {
84 $this->assertEquals(
true,
85 preg_match(
'!^[0-9a-f]{8}-[0-9a-f]{4}-1[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$!', $id ),
86 "UID $id has the right format" );
90 $this->assertEquals(
true,
91 preg_match(
'!^[0-9a-f]{12}1[0-9a-f]{3}[89ab][0-9a-f]{15}$!', $id ),
92 "UID $id has the right format" );
95 $this->assertEquals(
true,
96 preg_match(
'!^[0-9a-f]{12}1[0-9a-f]{3}[89ab][0-9a-f]{15}$!', $id ),
97 "UID $id has the right format" );
100 $this->assertEquals( array_unique( $ids ), $ids,
"All generated IDs are unique." );
108 for ( $i = 0; $i < 100; $i++ ) {
111 $this->assertEquals(
true,
112 preg_match(
'!^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$!', $id ),
113 "UID $id has the right format" );
116 $this->assertEquals( array_unique( $ids ), $ids,
'All generated IDs are unique.' );
123 for ( $i = 0; $i < 100; $i++ ) {
125 $this->assertEquals(
true,
126 preg_match(
'!^[0-9a-f]{12}4[0-9a-f]{3}[89ab][0-9a-f]{15}$!', $id ),
127 "UID $id has the right format" );
135 for ( $i = 0; $i < 100; $i++ ) {
137 $this->assertEquals(
true,
138 preg_match(
'!^[0-9a-f]{12}4[0-9a-f]{3}[89ab][0-9a-f]{15}$!', $id ),
139 "UID $id has the right format" );
150 $this->assertInternalType(
'float', $id1,
"ID returned as float" );
151 $this->assertInternalType(
'float', $id2,
"ID returned as float" );
152 $this->assertGreaterThan( 0, $id1,
"ID greater than 1" );
153 $this->assertGreaterThan( $id1, $id2,
"IDs increasing in value" );
162 foreach ( $ids
as $id ) {
163 $this->assertInternalType(
'float', $id,
"ID returned as float" );
164 $this->assertGreaterThan( 0, $id,
"ID greater than 1" );
166 $this->assertGreaterThan( $lastId, $id,
"IDs increasing in value" );