vendredi 31 juillet 2020

How to test simple boolean functions?

Im having some issues to understand testing, since I almost never find it neccessary.

If I have simple functions like

function isMovementOutOfBounds(newPosition) {
  if (newPosition[0] > input[0][0] || newPosition[0] < 0 || newPosition[1] > input[0][1] || newPosition[1] < 0) {
    return true;
  }
  return false;
}

or

function isMovementForbidden(forbiddenMovements, initialPosition, newPosition) {
  function isArrayInArray(arr, item) {
    const item_as_string = JSON.stringify(item);
    const contains = arr.some((ele) => JSON.stringify(ele) === item_as_string);
    return contains;
  }
  const newMovement = [initialPosition, newPosition];

  if (isArrayInArray(forbiddenMovements, newMovement)) {
    return true;
  }
  return false;
}

Should they even be tested? They have always a return, and its always boolean. So I don't understand if its really necessary to test it.

Maybe I should test for the type of input they receive?

It all seems dumb to me, how could I test those functions? Any idea of what should I look for?

Aucun commentaire:

Enregistrer un commentaire