1
1
import { copy } from '@array-like/copy' ;
2
- import { entropy } from './fixtures.js' ;
2
+ import { arrayValue , entropy } from './fixtures.js' ;
3
3
import { increasing , decreasing } from './defaults.js' ;
4
4
5
5
const macro = (
@@ -9,13 +9,12 @@ const macro = (
9
9
const { randint} = entropy ( seed ) ;
10
10
// SETUP REF ARRAY
11
11
12
- let _max = max ;
13
- ++ _max ;
14
- let _min = min ;
15
- -- _min ;
12
+ const _max = arrayValue ( array , max + 1 ) ;
13
+ const _min = arrayValue ( array , min - 1 ) ;
16
14
// eslint-disable-next-line new-cap
17
15
const ref = new array ( length ) ;
18
- for ( let j = 0 ; j < length ; ++ j ) ref [ j ] = randint ( min , _max ) ;
16
+ for ( let j = 0 ; j < length ; ++ j )
17
+ ref [ j ] = arrayValue ( array , randint ( min , max + 1 ) ) ;
19
18
Array . prototype . sort . call ( ref , delta ) ;
20
19
21
20
// SETUP TEST ARRAY
@@ -28,25 +27,25 @@ const macro = (
28
27
// CHECK > OUTER BOUND
29
28
let v = delta ( - 1 , 0 ) < 0 ? _max : _min ;
30
29
let r = search ( delta , a , 0 , length , v ) ;
31
- t . false ( found ( delta , a , 0 , length , r ) , `not found ${ v } ` ) ;
32
- t . is ( pos ( delta , a , 0 , length , r ) , length , `where === ${ length } ` ) ;
30
+ t . false ( found ( r ) , `not found ${ v } ` ) ;
31
+ t . is ( pos ( r ) , length , `where === ${ length } ` ) ;
33
32
34
33
// CHECK BODY
35
34
for ( let i = length - 1 ; i >= 0 ; -- i ) {
36
35
r = search ( delta , a , 0 , length , a [ i ] ) ;
37
- t . true ( found ( delta , a , 0 , length , r ) , `found a[${ i } ]` ) ;
38
- t . deepEqual ( a [ pos ( delta , a , 0 , length , r ) ] , a [ i ] , `val === ${ a [ i ] } ` ) ;
36
+ t . true ( found ( r ) , `found a[${ i } ]` ) ;
37
+ t . deepEqual ( a [ pos ( r ) ] , a [ i ] , `val === ${ a [ i ] } ` ) ;
39
38
}
40
39
41
40
// CHECK < OUTER BOUND
42
41
v = delta ( - 1 , 0 ) > 0 ? _max : _min ;
43
42
r = search ( delta , a , 0 , length , v ) ;
44
- t . false ( found ( delta , a , 0 , length , r ) , 'not found -1' ) ;
45
- t . is ( pos ( delta , a , 0 , length , r ) , 0 , 'where === 0' ) ;
43
+ t . false ( found ( r ) , 'not found -1' ) ;
44
+ t . is ( pos ( r ) , 0 , 'where === 0' ) ;
46
45
} else {
47
- const r = search ( delta , a , 0 , length , - 1 ) ;
48
- t . false ( found ( delta , a , 0 , length , r ) , 'not found -1' ) ;
49
- t . is ( pos ( delta , a , 0 , length , r ) , 0 , 'where === 0' ) ;
46
+ const r = search ( delta , a , 0 , length , _min ) ;
47
+ t . false ( found ( r ) , 'not found -1' ) ;
48
+ t . is ( pos ( r ) , 0 , 'where === 0' ) ;
50
49
}
51
50
52
51
// CHECK NOT MODIFIED
0 commit comments