mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
CustomNodeAppender incorrect index fix
This commit is contained in:
Vendored
+1
-1
@@ -856,7 +856,7 @@ var CustomNodeAppender = function () {
|
||||
}
|
||||
return Utils_1.Utils.getRandomGenerator().integer({
|
||||
min: 0,
|
||||
max: Math.round(blockStatementBodyLength * threshold)
|
||||
max: Math.round((blockStatementBodyLength - 1) * threshold)
|
||||
});
|
||||
}
|
||||
}, {
|
||||
|
||||
@@ -54,7 +54,7 @@ export class CustomNodeAppender {
|
||||
|
||||
return Utils.getRandomGenerator().integer({
|
||||
min: 0,
|
||||
max: Math.round(blockStatementBodyLength * threshold)
|
||||
max: Math.round((blockStatementBodyLength - 1) * threshold)
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -277,25 +277,24 @@ describe('CustomNodeAppender', () => {
|
||||
it('should returns random index between 0 and index based on threshold value', () => {
|
||||
let index: number;
|
||||
|
||||
for (let i = 0; i < 10; i++) {
|
||||
for (let i: number = 0; i < 10; i++) {
|
||||
index = CustomNodeAppender.getIndexByThreshold(100, 0.1);
|
||||
|
||||
assert.isAtLeast(index, 0);
|
||||
assert.isAtMost(index, 10);
|
||||
}
|
||||
|
||||
for (let i = 0; i < 10; i++) {
|
||||
for (let i: number = 0; i < 10; i++) {
|
||||
index = CustomNodeAppender.getIndexByThreshold(10, 0.5);
|
||||
|
||||
assert.isAtLeast(index, 0);
|
||||
assert.isAtMost(index, 5);
|
||||
}
|
||||
|
||||
for (let i = 0; i < 10; i++) {
|
||||
for (let i: number = 0; i < 10; i++) {
|
||||
index = CustomNodeAppender.getIndexByThreshold(1, 1);
|
||||
|
||||
assert.isAtLeast(index, 0);
|
||||
assert.isAtMost(index, 1);
|
||||
assert.equal(index, 0);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
+1
-1
@@ -67,7 +67,7 @@
|
||||
"no-null-keyword": false,
|
||||
"no-reference": true,
|
||||
"no-require-imports": false,
|
||||
"no-shadowed-variable": true,
|
||||
"no-shadowed-variable": false,
|
||||
"no-string-literal": true,
|
||||
"no-switch-case-fall-through": false,
|
||||
"no-trailing-whitespace": true,
|
||||
|
||||
Reference in New Issue
Block a user