瀏覽代碼

CustomNodeAppender incorrect index fix

sanex3339 8 年之前
父節點
當前提交
791e819a6f
共有 4 個文件被更改,包括 7 次插入8 次删除
  1. 1 1
      dist/index.js
  2. 1 1
      src/custom-nodes/CustomNodeAppender.ts
  3. 4 5
      test/unit-tests/custom-nodes/CustomNodeAppender.spec.ts
  4. 1 1
      tslint.json

+ 1 - 1
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)
             });
         }
     }, {

+ 1 - 1
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)
         });
     }
 

+ 4 - 5
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);
             }
         });
     });

+ 1 - 1
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,