Because of the way Educative tests multiple inputs together, I keep getting test fails even though my code is right and it works fine. Is there a way to test only for a single input instead of multiple?
Here’s an example:
function gpaPoint($grade) {
switch ($grade) {
case ‘A+’:
echo 4;
break;
case ‘A’:
echo 4;
break;
case ‘A-’:
echo 3.7;
break;
case ‘B+’:
echo 3.3;
break;
case ‘B’:
echo 3;
break;
case ‘B-’:
echo 2.8;
break;
case ‘C+’:
echo 2.5;
break;
case ‘C’:
echo 2;
break;
case ‘C-’:
echo 1.8;
break;
case ‘D’:
echo 1.5;
break;
case ‘F’:
echo 0;
break;
default:
echo ‘Incorrect grade entered, check your input.’;
break;
}
}
This code works fine when I test for a single input by calling the function like:
gpaPoint(‘B+’);
But when Educative tests it for multiple inputs at once, we get an output like:
3.72.5430 (the tests were run simultaneously for gpaPoint(A-), gpaPoint(C+), gpaPoint(A), gpaPoint(B), gpaPoint(F) so the answers are 3.7, 2.5, 4, 3, 0 respectively.
As a result Educative is showing that my test failed even though my code was correct. Is there a way to fix this as it is annoying?