File tree Expand file tree Collapse file tree 6 files changed +17
-7
lines changed Expand file tree Collapse file tree 6 files changed +17
-7
lines changed Original file line number Diff line number Diff line change 1
1
export class ID {
2
- function uniqid(): string {
2
+ static uniqid(): string {
3
3
const now = new Date();
4
4
const secondsSinceEpoch = Math.floor(now.getTime() / 1000);
5
5
const msecs = now.getTime() - secondsSinceEpoch * 1000;
@@ -15,7 +15,7 @@ export class ID {
15
15
}
16
16
17
17
public static unique(padding: number = 5): string {
18
- const baseId = uniqid();
18
+ const baseId = ID. uniqid();
19
19
let randomPadding = '';
20
20
21
21
for (let i = 0; i < padding; i++) {
Original file line number Diff line number Diff line change
1
+ using System;
2
+
1
3
namespace {{ spec .title | caseUcfirst }}
2
4
{
3
5
public static class ID
@@ -16,6 +18,7 @@ namespace {{ spec.title | caseUcfirst }}
16
18
17
19
public static string Unique(int padding = 5)
18
20
{
21
+ var random = new Random();
19
22
var baseId = UniqID();
20
23
var randomPadding = "";
21
24
Original file line number Diff line number Diff line change 1
1
class ID {
2
- static function uniqid() {
2
+ static uniqid = () => {
3
3
const now = new Date();
4
4
const secondsSinceEpoch = Math.floor(now.getTime() / 1000);
5
5
const msecs = now.getTime() - secondsSinceEpoch * 1000;
@@ -11,7 +11,7 @@ class ID {
11
11
}
12
12
13
13
static unique = (padding = 7) => {
14
- const baseId = uniqid();
14
+ const baseId = ID. uniqid();
15
15
let randomPadding = '';
16
16
17
17
for (let i = 0; i < padding; i++) {
Original file line number Diff line number Diff line change @@ -16,6 +16,6 @@ class ID:
16
16
17
17
@staticmethod
18
18
def unique(padding = 5):
19
- base_id = uniqid()
19
+ base_id = uniqid()
20
20
random_padding = ''.join(random.choice('0123456789abcdef') for _ in range(padding))
21
21
return base_id + random_padding
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ module {{spec.title | caseUcfirst}}
14
14
id
15
15
end
16
16
17
- def self.unique_id (padding=5)
17
+ def self.unique (padding=5)
18
18
base_id = uniqid
19
19
random_padding = SecureRandom.hex(padding / 2)
20
20
random_padding = random_padding[0...padding]
Original file line number Diff line number Diff line change @@ -212,7 +212,14 @@ public function testHTTPSuccess(): void
212
212
$ this ->assertGreaterThanOrEqual (count ($ this ->expectedOutput ), count ($ output ));
213
213
214
214
foreach ($ this ->expectedOutput as $ i => $ row ) {
215
- $ this ->assertEquals ($ output [$ i ], $ row );
215
+ // Check we are generating ID's correctly
216
+ if ($ row == 'unique() ' ) {
217
+ $ this ->assertNotEmpty ($ output [$ i ]);
218
+ $ this ->assertIsString ($ output [$ i ]);
219
+ $ this ->assertNotEquals ($ output [$ i ], 'unique() ' );
220
+ } else {
221
+ $ this ->assertEquals ($ output [$ i ], $ row );
222
+ }
216
223
}
217
224
}
218
225
You can’t perform that action at this time.
0 commit comments