websnark/test/helpers/helpers.js

26 lines
638 B
JavaScript
Raw Normal View History

2019-06-25 12:08:40 +03:00
const bigInt = require("big-integer");
function genValues(n, neg, bitsPerWord) {
bitsPerWord = bitsPerWord || 32;
const res = [];
res.push(bigInt.zero);
for (let i=0; i<n; i++) {
if (i>0) {
res.push( bigInt.one.shiftLeft(bitsPerWord*i).minus(1));
}
if (i<n-1) {
res.push( bigInt.one.shiftLeft(bitsPerWord*i));
res.push( bigInt.one.shiftLeft(bitsPerWord*i).add(1));
}
}
if (neg) {
const nt= res.length;
for (let i=0; i<nt; i++) res.push(bigInt.zero.minus(res[i]));
}
return res;
}
module.exports.genValues = genValues;