@@ -9,46 +9,42 @@ import * as array from "@aureooms/js-array" ;
9
9
import operator from "@aureooms/js-operator" ;
10
10
11
11
12
- function one ( type , shuffle ) {
12
+ function one ( type , shuffle_name , shuffle ) {
13
13
14
- var calloc , a , b , n , range ;
14
+ const type_name = type . toString ( ) . split ( ' ' ) [ 1 ] . slice ( 0 , - 2 ) ;
15
15
16
- calloc = mem . _calloc ( type ) ;
16
+ const calloc = mem . _calloc ( type ) ;
17
17
18
- n = 100 ;
18
+ const n = 100 ;
19
19
20
- a = calloc ( n ) ;
21
- b = calloc ( n ) ;
20
+ const a = calloc ( n ) ;
21
+ const b = calloc ( n ) ;
22
22
23
23
array . iota ( a , 0 , n , 0 ) ;
24
24
25
- range = function ( i , j ) {
25
+ const range = function ( i , j ) {
26
26
27
- var name ;
27
+ const name = util . format ( "shuffle ( %s , %s , %s, %s )" , type_name , shuffle_name , i , j ) ;
28
28
29
- name = util . format ( "shuffle ( %s, %s )" , i , j ) ;
30
-
31
- test ( name , t => {
32
-
33
- var it , msg , _a , _b ;
29
+ test ( name , t => {
34
30
35
31
array . copy ( a , 0 , n , b , 0 ) ;
36
32
shuffle ( b , i , j ) ;
37
33
38
- for ( it = 0 ; it < i ; ++ it ) {
39
- msg = util . format ( "b[%d] === a[%d]" , it , it ) ;
34
+ for ( let it = 0 ; it < i ; ++ it ) {
35
+ const msg = util . format ( "b[%d] === a[%d]" , it , it ) ;
40
36
t . deepEqual ( b [ it ] , a [ it ] , msg ) ;
41
37
}
42
38
43
- _a = Array . prototype . slice . call ( a , i , j ) . sort ( operator . sub ) ;
44
- _b = Array . prototype . slice . call ( b , i , j ) . sort ( operator . sub ) ;
39
+ const _a = Array . prototype . slice . call ( a , i , j ) . sort ( operator . sub ) ;
40
+ const _b = Array . prototype . slice . call ( b , i , j ) . sort ( operator . sub ) ;
45
41
46
- msg = "shuffled region contains same elements as original" ;
42
+ const msg = "shuffled region contains same elements as original" ;
47
43
48
44
t . deepEqual ( _b , _a , msg ) ;
49
45
50
- for ( it = j ; it < n ; ++ it ) {
51
- msg = util . format ( "b[%d] === a[%d]" , it , it ) ;
46
+ for ( let it = j ; it < n ; ++ it ) {
47
+ const msg = util . format ( "b[%d] === a[%d]" , it , it ) ;
52
48
t . deepEqual ( b [ it ] , a [ it ] , msg ) ;
53
49
}
54
50
@@ -60,9 +56,6 @@ test( name, t => {
60
56
range ( 20 , n ) ;
61
57
range ( 0 , n - 20 ) ;
62
58
range ( 10 , n - 10 ) ;
63
- range ( 10 , n - 10 ) ;
64
-
65
-
66
59
67
60
} ;
68
61
@@ -80,16 +73,16 @@ const types = [
80
73
] ;
81
74
82
75
const algorithms = [
83
- random . _shuffle ( random . _fisheryates ( random . randint ) ) ,
84
- random . _shuffle ( random . sample ) ,
85
- random . shuffle
76
+ [ 'shuffle based on Fisher-Yates' , random . _shuffle ( random . _fisheryates ( random . randint ) ) ] ,
77
+ [ 'shuffle based on random.sample' , random . _shuffle ( random . sample ) ] ,
78
+ [ 'API' , random . shuffle ] ,
86
79
] ;
87
80
88
81
types . forEach ( function ( type ) {
89
82
90
- algorithms . forEach ( function ( algorithm ) {
83
+ algorithms . forEach ( function ( [ name , algorithm ] ) {
91
84
92
- one ( type , algorithm ) ;
85
+ one ( type , name , algorithm ) ;
93
86
94
87
} ) ;
95
88
0 commit comments