samedi 12 septembre 2020

How do you know if loop or double loop is used in a function when unit testing?

I am new to unit testing, and would like to check if any line of code to contain double loop specifically.

I am currently studying at bootcamp and they somehow check if my solution contains specific loop (like while loop) or if I used nested loop as below.

Test Code
function () {
    expect(DOUBLE_LOOP_EXP.test(funcBody)).to.be.equal(true);
  } 

To clarify, below is my function that's been tested through above criterion;

function makePermutations(str) {
  let result = '';
  for (let i = 0; i < str.length; i++) {
    for (let j = 0; j < str.length; j++) {
      result += str[i] + str[j] + ',';
    }
  }
  return result.slice(0, result.length - 1);
}
module.exports = makePermutations;

Unfortunately, there's no way to know whats inside that DOUBLE_LOOP_EXP.test. Please advise.

Aucun commentaire:

Enregistrer un commentaire