Skip to content

Commit

Permalink
#2 ensure no side effects on modifying the results
Browse files Browse the repository at this point in the history
  • Loading branch information
shubhranshu committed Apr 26, 2020
1 parent 363c136 commit 31dabb7
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ const calculateRatio = (x, y) => {
}

return {
match,
sortedRatios,
match: { ...match },
sortedRatios: [...sortedRatios],
};
};

Expand Down
10 changes: 0 additions & 10 deletions test/sample.js

This file was deleted.

9 changes: 0 additions & 9 deletions test/testRatios.js

This file was deleted.

22 changes: 22 additions & 0 deletions test/tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import test from 'ava';
import { calculateRatio } from '../src/index';

test('constructor is ok', (t) => {
var rslt = calculateRatio(2, 1);
t.pass();
});

test('test ratio 2:1', (t) => {
var rslt = calculateRatio(2, 1);
t.assert(rslt.match.ratio === '2:1');
});

test('test result modifications has no side effects', (t)=>{
var rslt = calculateRatio(2, 1);
t.assert(rslt.match.ratio === '2:1');
delete rslt.match.ratio;
var rslt = calculateRatio(200, 100);
t.assert(rslt.match.ratio === '2:1');
})

test

0 comments on commit 31dabb7

Please sign in to comment.