@@ -9,46 +9,42 @@ import * as array from "@aureooms/js-array" ;
99import operator from "@aureooms/js-operator" ;
1010
1111
12- function one ( type , shuffle ) {
12+ function one ( type , shuffle_name , shuffle ) {
1313
14- var calloc , a , b , n , range ;
14+ const type_name = type . toString ( ) . split ( ' ' ) [ 1 ] . slice ( 0 , - 2 ) ;
1515
16- calloc = mem . _calloc ( type ) ;
16+ const calloc = mem . _calloc ( type ) ;
1717
18- n = 100 ;
18+ const n = 100 ;
1919
20- a = calloc ( n ) ;
21- b = calloc ( n ) ;
20+ const a = calloc ( n ) ;
21+ const b = calloc ( n ) ;
2222
2323 array . iota ( a , 0 , n , 0 ) ;
2424
25- range = function ( i , j ) {
25+ const range = function ( i , j ) {
2626
27- var name ;
27+ const name = util . format ( "shuffle ( %s , %s , %s, %s )" , type_name , shuffle_name , i , j ) ;
2828
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 => {
3430
3531 array . copy ( a , 0 , n , b , 0 ) ;
3632 shuffle ( b , i , j ) ;
3733
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 ) ;
4036 t . deepEqual ( b [ it ] , a [ it ] , msg ) ;
4137 }
4238
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 ) ;
4541
46- msg = "shuffled region contains same elements as original" ;
42+ const msg = "shuffled region contains same elements as original" ;
4743
4844 t . deepEqual ( _b , _a , msg ) ;
4945
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 ) ;
5248 t . deepEqual ( b [ it ] , a [ it ] , msg ) ;
5349 }
5450
@@ -60,9 +56,6 @@ test( name, t => {
6056 range ( 20 , n ) ;
6157 range ( 0 , n - 20 ) ;
6258 range ( 10 , n - 10 ) ;
63- range ( 10 , n - 10 ) ;
64-
65-
6659
6760} ;
6861
@@ -80,16 +73,16 @@ const types = [
8073] ;
8174
8275const 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 ] ,
8679] ;
8780
8881types . forEach ( function ( type ) {
8982
90- algorithms . forEach ( function ( algorithm ) {
83+ algorithms . forEach ( function ( [ name , algorithm ] ) {
9184
92- one ( type , algorithm ) ;
85+ one ( type , name , algorithm ) ;
9386
9487 } ) ;
9588
0 commit comments