Skip to content

Commit 2ef9027

Browse files
🔍 test: Fix tests.
1 parent e77f079 commit 2ef9027

File tree

2 files changed

+41
-52
lines changed

2 files changed

+41
-52
lines changed

test/src/sample.js

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,46 +9,42 @@ import * as array from "@aureooms/js-array" ;
99
import operator from "@aureooms/js-operator" ;
1010

1111

12-
function one ( type, sample ) {
12+
function one ( type, sample_name, sample ) {
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 ( k, i, j ) {
25+
const range = function ( k, i, j ) {
2626

27-
var name;
27+
const name = util.format( "sample ( %s, %s, %s, %s, %s )", type_name, sample_name, k, i, j );
2828

29-
name = util.format( "sample ( %s, %s, %s )", k, 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
sample( k, 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

@@ -80,15 +76,15 @@ const types = [
8076
];
8177

8278
const algorithms = [
83-
random._fisheryates( random.randint ),
84-
random.sample
79+
[ 'Fisher-Yates' , random._fisheryates( random.randint ) ] ,
80+
[ 'API' , random.sample ] ,
8581
];
8682

8783
types.forEach( function ( type ) {
8884

89-
algorithms.forEach( function ( algorithm ) {
85+
algorithms.forEach( function ( [name, algorithm] ) {
9086

91-
one( type, algorithm );
87+
one( type, name, algorithm );
9288

9389
});
9490

test/src/shuffle.js

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,46 +9,42 @@ import * as array from "@aureooms/js-array" ;
99
import 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

8275
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 ],
8679
];
8780

8881
types.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

Comments
 (0)