Skip to content

Commit

Permalink
Fix complexity rate NaN
Browse files Browse the repository at this point in the history
  • Loading branch information
xcatliu committed Dec 5, 2017
1 parent 550a260 commit 7f62d65
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 43 deletions.
5 changes: 4 additions & 1 deletion src/ComplexityChecker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ class ComplexityChecker extends BaseChecker {
return false;
});

let percentage = numberOfHighComplexityFunctions / numberOfFunctions * 100;
let percentage = 0;
if (numberOfFunctions > 0) {
percentage = numberOfHighComplexityFunctions / numberOfFunctions * 100;
}
percentage = percentage.toFixed(2);

const result = {
Expand Down
42 changes: 0 additions & 42 deletions test/integration/checkReportEmptyOutputs.test.js

This file was deleted.

16 changes: 16 additions & 0 deletions test/integration/checkWithEmptyOutputs.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const assert = require('chai').assert;

const CodeQualityChecker = require('../../');
const codeQualityChecker = new CodeQualityChecker();

describe('Check with empty input', () => {
const cqcResult = codeQualityChecker.check([
'test/sample/not-exist-path.js'
]);
it('should have correct result', () => {
assert.equal(cqcResult.base.numberOfFiles, 0);
assert.equal(cqcResult.sloc.source, 0);
assert.equal(cqcResult.jscpd.percentage, '0.00');
assert.equal(cqcResult.complexity.percentage, '0.00');
});
});

0 comments on commit 7f62d65

Please sign in to comment.