From 791e819a6fdf9d5ae938d945363aab4f8a2d2708 Mon Sep 17 00:00:00 2001 From: sanex3339 Date: Mon, 10 Oct 2016 13:30:17 +0300 Subject: [PATCH] CustomNodeAppender incorrect index fix --- dist/index.js | 2 +- src/custom-nodes/CustomNodeAppender.ts | 2 +- test/unit-tests/custom-nodes/CustomNodeAppender.spec.ts | 9 ++++----- tslint.json | 2 +- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/dist/index.js b/dist/index.js index a305abdd..96391bf2 100644 --- a/dist/index.js +++ b/dist/index.js @@ -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) }); } }, { diff --git a/src/custom-nodes/CustomNodeAppender.ts b/src/custom-nodes/CustomNodeAppender.ts index ccb4698c..0f99ba74 100644 --- a/src/custom-nodes/CustomNodeAppender.ts +++ b/src/custom-nodes/CustomNodeAppender.ts @@ -54,7 +54,7 @@ export class CustomNodeAppender { return Utils.getRandomGenerator().integer({ min: 0, - max: Math.round(blockStatementBodyLength * threshold) + max: Math.round((blockStatementBodyLength - 1) * threshold) }); } diff --git a/test/unit-tests/custom-nodes/CustomNodeAppender.spec.ts b/test/unit-tests/custom-nodes/CustomNodeAppender.spec.ts index 776a31b1..17c58c67 100644 --- a/test/unit-tests/custom-nodes/CustomNodeAppender.spec.ts +++ b/test/unit-tests/custom-nodes/CustomNodeAppender.spec.ts @@ -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); } }); }); diff --git a/tslint.json b/tslint.json index ae1eda38..dcedfa2a 100644 --- a/tslint.json +++ b/tslint.json @@ -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,