-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: writing some unit tests for new classes
- Loading branch information
1 parent
755367d
commit 4b674b6
Showing
6 changed files
with
185 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* eslint-env mocha */ | ||
|
||
const chai = require('chai'); | ||
chai.should(); | ||
|
||
const BRDA = require('../../lib/BRDA'); | ||
|
||
describe('Unit | BRDA', function () { | ||
it('should be constructable with the new operator', async function () { | ||
const instance = new BRDA(10, 20, 30, 40); | ||
|
||
instance.should.be.instanceOf(BRDA); | ||
instance.should.have.property('lineNumber', 10); | ||
instance.should.have.property('blockNumber', 20); | ||
instance.should.have.property('branchNumber', 30); | ||
instance.should.have.property('hits', 40); | ||
}); | ||
|
||
it('should be able to parse a string into meaningful values', async function () { | ||
BRDA.parseString('1,2,3,4').should.eql([1, 2, 3, 4]); | ||
BRDA.parseString('5,6,7,-').should.eql([5, 6, 7, '-']); | ||
}); | ||
|
||
it('should output a valid string representation of its content', async function () { | ||
new BRDA(10, 20, 30, 40).toString().should.equal('BRDA:10,20,30,40\n'); | ||
}); | ||
|
||
it('should accurately increment its hit count', async function () { | ||
let instance = new BRDA(1, 2, 3, '-'); | ||
instance.should.have.property('hits', '-'); | ||
|
||
instance.addHits('-'); | ||
instance.should.have.property('hits', '-'); | ||
|
||
instance.addHits(1); | ||
instance.should.have.property('hits', 1); | ||
|
||
instance = new BRDA(1, 2, 3, 4); | ||
instance.should.have.property('hits', 4); | ||
|
||
instance.addHits('-'); | ||
instance.should.have.property('hits', 4); | ||
|
||
instance.addHits(1); | ||
instance.should.have.property('hits', 5); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* eslint-env mocha */ | ||
|
||
const chai = require('chai'); | ||
chai.should(); | ||
|
||
const CoverageFile = require('../../lib/CoverageFile'); | ||
|
||
describe('Unit | CoverageFile', function () { | ||
it('should be constructable with the new operator', async function () { | ||
const instance = new CoverageFile('test-lcov.info'); | ||
|
||
instance.should.be.instanceOf(CoverageFile); | ||
instance.should.have.property('filename', 'test-lcov.info'); | ||
instance.should.have.property('BRDARecords').eql([]); | ||
instance.should.have.property('DARecords').eql([]); | ||
}); | ||
|
||
it('should allow DA records to be added', async function () { | ||
const instance = new CoverageFile('test-lcov.info'); | ||
|
||
instance.DARecords.should.have.length(0); | ||
|
||
instance.addDA(10, 1); | ||
instance.DARecords.should.have.length(1); | ||
instance.DARecords[0].should.have.property('lineNumber', 10); | ||
instance.DARecords[0].should.have.property('hits', 1); | ||
|
||
instance.parseDA('20,2'); | ||
instance.DARecords.should.have.length(2); | ||
instance.DARecords[1].should.have.property('lineNumber', 20); | ||
instance.DARecords[1].should.have.property('hits', 2); | ||
}); | ||
|
||
it('should add hits to an existing DA record when one exists, instead of creating a duplicate', async function () { | ||
const instance = new CoverageFile('test-lcov.info'); | ||
|
||
instance.addDA(10, 1); | ||
instance.DARecords.should.have.length(1); | ||
instance.DARecords[0].should.have.property('lineNumber', 10); | ||
instance.DARecords[0].should.have.property('hits', 1); | ||
|
||
instance.addDA(10, 3); | ||
instance.DARecords.should.have.length(1); | ||
instance.DARecords[0].should.have.property('lineNumber', 10); | ||
instance.DARecords[0].should.have.property('hits', 4); | ||
}); | ||
|
||
it('should allow BRDA records to be added', async function () { | ||
const instance = new CoverageFile('test-lcov.info'); | ||
|
||
instance.BRDARecords.should.have.length(0); | ||
|
||
instance.addBRDA(10, 20, 30, 40); | ||
instance.BRDARecords.should.have.length(1); | ||
instance.BRDARecords[0].should.have.property('lineNumber', 10); | ||
instance.BRDARecords[0].should.have.property('blockNumber', 20); | ||
instance.BRDARecords[0].should.have.property('branchNumber', 30); | ||
instance.BRDARecords[0].should.have.property('hits', 40); | ||
|
||
instance.parseBRDA('1,2,3,4'); | ||
instance.BRDARecords.should.have.length(2); | ||
instance.BRDARecords[1].should.have.property('lineNumber', 1); | ||
instance.BRDARecords[1].should.have.property('blockNumber', 2); | ||
instance.BRDARecords[1].should.have.property('branchNumber', 3); | ||
instance.BRDARecords[1].should.have.property('hits', 4); | ||
}); | ||
|
||
it('should add hits to an existing BRDA record when one exists, instead of creating a duplicate', async function () { | ||
const instance = new CoverageFile('test-lcov.info'); | ||
|
||
instance.addBRDA(10, 20, 30, 1); | ||
instance.BRDARecords.should.have.length(1); | ||
instance.BRDARecords[0].should.have.property('lineNumber', 10); | ||
instance.BRDARecords[0].should.have.property('blockNumber', 20); | ||
instance.BRDARecords[0].should.have.property('branchNumber', 30); | ||
instance.BRDARecords[0].should.have.property('hits', 1); | ||
|
||
instance.addBRDA(10, 20, 30, 3); | ||
instance.BRDARecords.should.have.length(1); | ||
instance.BRDARecords[0].should.have.property('lineNumber', 10); | ||
instance.BRDARecords[0].should.have.property('blockNumber', 20); | ||
instance.BRDARecords[0].should.have.property('branchNumber', 30); | ||
instance.BRDARecords[0].should.have.property('hits', 4); | ||
}); | ||
|
||
it('should output a valid string representation of its content', async function () { | ||
const instance = new CoverageFile('test-lcov.info'); | ||
|
||
instance.addBRDA(10, 20, 30, 40); | ||
instance.addDA(50, 60); | ||
|
||
instance | ||
.toString() | ||
.should.equal( | ||
'SF:test-lcov.info\n' + | ||
'DA:50,60\n' + | ||
'BRDA:10,20,30,40\n' + | ||
'end_of_record\n' | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* eslint-env mocha */ | ||
|
||
const chai = require('chai'); | ||
chai.should(); | ||
|
||
const DA = require('../../lib/DA'); | ||
|
||
describe('Unit | DA', function () { | ||
it('should be constructable with the new operator', async function () { | ||
const instance = new DA(10, 20); | ||
|
||
instance.should.be.instanceOf(DA); | ||
instance.should.have.property('lineNumber', 10); | ||
instance.should.have.property('hits', 20); | ||
}); | ||
|
||
it('should be able to parse a string into meaningful values', async function () { | ||
DA.parseString('1,2').should.eql([1, 2]); | ||
}); | ||
|
||
it('should output a valid string representation of its content', async function () { | ||
new DA(10, 20).toString().should.equal('DA:10,20\n'); | ||
}); | ||
|
||
it('should accurately increment its hit count', async function () { | ||
const instance = new DA(1, 2); | ||
instance.should.have.property('hits', 2); | ||
|
||
instance.addHits(1); | ||
instance.should.have.property('hits', 3); | ||
}); | ||
}); |