Skip to content

Commit

Permalink
testing and fixing calculator
Browse files Browse the repository at this point in the history
  • Loading branch information
Idrinth committed Jul 22, 2020
1 parent c2c501c commit 4240e62
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@idrinth/api-bench",
"description": "A library to benchmark apis, no matter if rest or soap",
"license": "MIT",
"version": "1.1.2",
"version": "1.1.3",
"homepage": "https://github.com/Idrinth/api-bench",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion src/worker/calculator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export = (result: ResultSet,): FinishedSet => {
max80: NaN,
};
}
const sorted100 = result.durations.sort();
const sorted100 = result.durations.sort((a:number, b:number) => a-b);
const center80 = sorted100.slice(
Math.floor(result.count * CONSTANTS.PERCENT10,),
Math.ceil(result.count * CONSTANTS.PERCENT90,),
Expand Down
48 changes: 48 additions & 0 deletions test/worker/calculator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,52 @@ describe('calculator', () => {
it('should be a function', () => {
expect(calculator,).to.be.a('function',);
},);
it('should return an empty set if not given data', () => {
expect(calculator({id:'##', errors: 5, durations: [], count: 9}),).to.deep.equal({
id: '##',
errors: 5,
msgs: {},
count: 9,
avg100: NaN,
median100: NaN,
min100: NaN,
max100: NaN,
avg80: NaN,
median80: NaN,
min80: NaN,
max80: NaN,
},);
},);
it('should return a set if given data', () => {
expect(calculator({id:'#1', errors: 5, msgs: {some: 5}, durations: [1,2,3,4], count: 9}),).to.deep.equal({
id: '#1',
errors: 5,
msgs: {some: 5},
count: 9,
avg100: 3,
median100: 3,
min100: 1,
max100: 4,
avg80: 3,
median80: 3,
min80: 1,
max80: 4,
},);
},);
it('should return a result if given data', () => {
expect(calculator({id:'k#1', errors: 5, msgs: {some: 5}, durations: [1,2,3,4,5,6,7,8,9,10,23,343,32,2,2], count: 15}),).to.deep.equal({
id: 'k#1',
errors: 5,
msgs: {some: 5},
count: 15,
avg100: 30,
median100: 172,
min100: 1,
max100: 343,
avg80: 9,
median80: 17,
min80: 2,
max80: 32,
},);
},);
},);

0 comments on commit 4240e62

Please sign in to comment.