Skip to content

Commit 68f6c54

Browse files
committedMar 23, 2021
👕 refactor: Lint sources and tests.
1 parent cc4f739 commit 68f6c54

File tree

10 files changed

+26
-30
lines changed

10 files changed

+26
-30
lines changed
 

Diff for: ‎_benchmark/index.js

+13-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
/* global BigInt */
2-
/* eslint-disable new-cap, no-new, no-unused-expressions */
1+
/* eslint-disable new-cap */
32

43
const ArgumentParser = require('argparse').ArgumentParser;
54
var benchmark = require('benchmark');
@@ -52,7 +51,7 @@ function add (op, ...args) {
5251
const key = op + '-' + args.join('-');
5352
benchmarks.push({
5453
name: key,
55-
start: function start () {
54+
start: function () {
5655
var suite = new benchmark.Suite();
5756

5857
console.log('Benchmarking: ' + key);
@@ -64,13 +63,13 @@ function add (op, ...args) {
6463

6564
const opFn = fns[name][op];
6665
if (!opFn) return;
67-
if (!(opFn instanceof Function)) throw new Error(`opFN is not a function: ${opFN}`) ;
66+
if (!(opFn instanceof Function)) throw new Error(`opFN is not a function: ${opFn}`) ;
6867
const fixture = fixtures[findex][name];
6968

7069
if (args.length === 1) {
7170
const x = fixture.args[args[0]];
7271
const outs = fixture.outs;
73-
const testFn = () => outs[key] = opFn(x) ;
72+
const testFn = () => { outs[key] = opFn(x) ; } ;
7473
suite.add(name + '#' + key, testFn, {
7574
onStart: findexRefresh,
7675
onCycle: findexRefresh
@@ -80,7 +79,7 @@ function add (op, ...args) {
8079
const a = fixture.args[args[0]];
8180
const b = fixture.args[args[1]];
8281
const outs = fixture.outs;
83-
const testFn = () => outs[key] = opFn(a, b) ;
82+
const testFn = () => { outs[key] = opFn(a, b) ; } ;
8483
suite.add(name + '#' + key, testFn, {
8584
onStart: findexRefresh,
8685
onCycle: findexRefresh
@@ -139,12 +138,12 @@ const fns = {
139138
div: (a,b) => a / b,
140139
mod: (a, b) => {
141140
const remainder = a % b;
142-
return remainder < 0 ? remainder + b : remainer;
141+
return remainder < 0 ? remainder + b : remainder;
143142
},
144143

145144
toRed: x => x % k256_BigInt,
146145
fromRed: x => x,
147-
sqrm: x => (a**2) % k256_BigInt,
146+
sqrm: x => (x**2) % k256_BigInt,
148147
powm: (a,b) => (a**b) % k256_BigInt,
149148
} ,
150149
'bn.js': {
@@ -270,7 +269,7 @@ const fns = {
270269
fromRed: x => x,
271270
toRed: x => x.mod(k256_bignum),
272271
powm: (a,b) => a.powm(b, k256_bignum),
273-
sqrm: x => a.pown(2, k256_bignum),
272+
sqrm: x => x.pown(2, k256_bignum),
274273
invm: x => x.invertm(k256_bignum),
275274
} ,
276275
sjcl: {
@@ -442,18 +441,18 @@ for ( let i = 0; i < NFIXTURES; ++i ) {
442441
}) ;
443442
} ) ;
444443

445-
for ( const key in results[i] ) {
444+
for ( const key of Object.keys(results[i]) ) {
446445
const theseResults = results[i][key] ;
447446
const distinctResults = new Set(Object.values(theseResults));
448-
if (distinctResults.size !== 1) {
447+
if (distinctResults.size === 1) {
448+
console.error(i, key, JSON.stringify(Object.keys(theseResults)), 'OK') ;
449+
}
450+
else {
449451
console.error('DIFFERENT OUTPUTS for', i, key) ;
450452
console.error(distinctResults) ;
451453
console.error(i, key, theseResults) ;
452454
console.error(fixtures[i]) ;
453455
}
454-
else {
455-
console.error(i, key, JSON.stringify(Object.keys(theseResults)), 'OK') ;
456-
}
457456
}
458457

459458
}

Diff for: ‎_profile/add.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const ArgumentParser = require('argparse').ArgumentParser;
55
//const itertools = require('@aureooms/js-itertools');
66
const XorShift128Plus = require('xorshift.js').XorShift128Plus;
77
const { ZZ , DEFAULT_DISPLAY_BASE , DEFAULT_REPRESENTATION_BASE } = require('..');
8-
const BN = require('bn.js');
8+
//const BN = require('bn.js');
99

1010
const parser = new ArgumentParser();
1111
parser.addArgument(['M'], {defaultValue: 1000, nargs: '?'});
@@ -56,4 +56,5 @@ for (let k = 0; k < N; ++k) {
5656
}
5757
console.timeEnd('loop');
5858

59+
// eslint-disable-next-line no-self-compare
5960
console.log(z.toString(16) === z.toString(16) ? 'OK' : 'ERROR: NOT OK');

Diff for: ‎_profile/iadd.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const ArgumentParser = require('argparse').ArgumentParser;
55
//const itertools = require('@aureooms/js-itertools');
66
const XorShift128Plus = require('xorshift.js').XorShift128Plus;
77
const { ZZ } = require('..');
8-
const BN = require('bn.js');
8+
//const BN = require('bn.js');
99

1010
const parser = new ArgumentParser();
1111
parser.addArgument(['M'], {defaultValue: 1000, nargs: '?'});

Diff for: ‎_profile/mod.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const ArgumentParser = require('argparse').ArgumentParser;
66
const XorShift128Plus = require('xorshift.js').XorShift128Plus;
77
const { THRESHOLD_MUL_TOOM22 , THRESHOLD_DIV_DC } = require('@aureooms/js-integer-big-endian');
88
const { ZZ , DEFAULT_DISPLAY_BASE , DEFAULT_REPRESENTATION_BASE } = require('..');
9-
const BN = require('bn.js');
109

1110
const parser = new ArgumentParser();
1211
parser.addArgument(['M'], {defaultValue: 1000, nargs: '?'});
@@ -47,4 +46,5 @@ for (let k = 0; k < N; ++k) {
4746
}
4847
console.timeEnd('loop');
4948

49+
// eslint-disable-next-line no-self-compare
5050
console.log(z.toString(16) === z.toString(16) ? 'OK' : 'ERROR: NOT OK');

Diff for: ‎_profile/mul.js

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const ArgumentParser = require('argparse').ArgumentParser;
66
const XorShift128Plus = require('xorshift.js').XorShift128Plus;
77
const { THRESHOLD_MUL_TOOM22 } = require('@aureooms/js-integer-big-endian');
88
const { ZZ } = require('..');
9-
const BN = require('bn.js');
109

1110
const parser = new ArgumentParser();
1211
parser.addArgument(['M'], {defaultValue: 1000, nargs: '?'});

Diff for: ‎src/Integer.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -308,13 +308,13 @@ export class Integer {
308308

309309
if ( other.is_negative ) {
310310

311-
if ( !this.is_negative ) {
312-
increment( r , q , 0 , q.length ) ;
313-
R.iadd( other ) ; // TODO optimize
311+
if ( this.is_negative ) {
312+
R.negate(); // TODO optimize
314313
}
315314

316315
else {
317-
R.negate(); // TODO optimize
316+
increment( r , q , 0 , q.length ) ;
317+
R.iadd( other ) ; // TODO optimize
318318
}
319319

320320
}

Diff for: ‎src/ZeroDivisionError.js

-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11

22
export class ZeroDivisionError extends Error {
33

4-
constructor ( message ) {
5-
super( message ) ;
6-
}
7-
84
toString ( ) {
95
return `ZeroDivisionError: ${this.message}` ;
106
}

Diff for: ‎test/src/Integer/divide_knowing_divisible_by.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import test from 'ava' ;
22

3-
import { ZZ , ZeroDivisionError } from '../../../src' ;
3+
import { ZZ } from '../../../src' ;
44

55
function macro ( t , a , b , q ) {
66
const A = ZZ.from(a) ;
@@ -12,7 +12,7 @@ function macro ( t , a , b , q ) {
1212
t.is(b.toString(), B.toString()) ;
1313
}
1414

15-
macro.title = ( providedTitle , a , b , q , r ) => `${a} divide_knowing_divisible_by ${b} = ${q}` ;
15+
macro.title = ( providedTitle , a , b , q ) => providedTitle || `${a} divide_knowing_divisible_by ${b} = ${q}` ;
1616

1717
test(macro, 3, 1, 3) ;
1818
test(macro, '123', 3, 41) ;

Diff for: ‎test/src/Integer/parity.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ test( odd , ZZ.from(2).pow(1234).subn(1) ) ;
2929
const N = 100 ;
3030
let x = ZZ.from(-N);
3131

32-
for ( const i of range(N) ) {
32+
// eslint-disable-next-line no-unused-vars
33+
for ( const _ of range(N) ) {
3334
test( even , x ) ;
3435
x = x.addn(1) ;
3536
test( odd , x ) ;

Diff for: ‎test/src/ZZ/from.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ test( 'ZZ.from()' , t => {
3939

4040
t.throws( () => ZZ.from({}) , TypeError ) ;
4141
t.throws( () => ZZ.from(new Date()) , TypeError ) ;
42-
t.throws( () => ZZ.from(new Regex()) , TypeError ) ;
42+
t.throws( () => ZZ.from(new RegExp()) , TypeError ) ;
4343

4444
t.throws( () => ZZ.from('') , ValueError ) ;
4545
t.throws( () => ZZ.from('-') , ValueError ) ;

0 commit comments

Comments
 (0)
Please sign in to comment.