Skip to content

Commit

Permalink
100 random test cases for split
Browse files Browse the repository at this point in the history
100 random test cases are added to the split function to prevent hardcoding. As the tests were previously defined, it was very easy to hardcode against them.
  • Loading branch information
sagarishere authored Jan 17, 2023
1 parent ed05457 commit 24dbe53
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions js/tests/unbreakable_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ t(({ eq }) => eq(split('rrirr', 'rr'), ['', 'i', '']))
t(({ eq }) => eq(split('Riad', ''), ['R', 'i', 'a', 'd']))
t(({ eq }) => eq(split('', 'Riad'), ['']))

///// HARDCODING PREVENTION //////
for (let i = 0; i < 100; i++) {
t(({eq}) => {
const randomString = Array.from({length: Math.floor(Math.random() * 100) + 1}, () => String.fromCharCode(Math.floor(Math.random() * 26) + 97)).join('');
const randomDelimiter = randomString[Math.floor(Math.random() * randomString.length)];
return eq(split(randomString, randomDelimiter), randomString.split(randomDelimiter))
});
}

t(() => join(['ee', 'ff', 'g', ''], ',') === 'ee,ff,g,')
t(() => join(['ggg', 'ddd', 'b'], ' - ') === 'ggg - ddd - b')
t(() => join(['a', 'b', 'c'], ' ') === 'a b c')

0 comments on commit 24dbe53

Please sign in to comment.