Relational DB : Bug in tests of "number_guessing" project

Hello,

I don’t know if this has already been reported (I didn’t found any topic in the forum) but as several persons reported in this forum, although I intensively tested it and never could lead it to fail , my number_guess.sh script couldn’t pass the coderoad tests. It appeared that error messages raised sometimes at step 8 (“8 Your script should print the correct welcome message for returning users”) at systematically at step 11 (“11 Your script should print the correct messages if they do not guess the correct number”).

As I couldn’t figure out where the mistake was, I took a look at the 1.1.test.js file and found what looks like a bug. At line 116 which is supposed to check if the output is “It’s greater…” OR “It’s lower…” there is an AND ( && ) operator (which is a condition impossible to satisfy) :

asssert(/It's higher than that, guess again:/.test(scriptOutput) && /It's lower than that, guess again:/.test(scriptOutput));

I changed it to || and everything went well (btw I was surprised to see that I had the credentials to edit/save the test code :slight_smile: ).

About the 8 test, I’m not sure because I don’t know any JS and JS regex, and the fail was not systematic, but it seems that it expects the output to change accordingly with the number of best guesses (singular/plural) : it is written guess(es) at the end of the sentence, which is not consistent with the way instructions are set out.

const reString = 'Welcome\\s+back, \\s+${usernae1}!\\s+You\\s+have\\s+played\\s+1\\s+games?,\\s+and\\s+your\\s+best\\s+took\\s+${guesses}\\s+guess(es)?\\.

Hope this can help…

I appreciate you digging into this @Jehadel.

I don’t think that’s the bug with the 11th test. The test runs your script and enters -1, then 1001, to ensure both the higher and lower messages are included in the script output. So, I believe the && is appropriate there. The issue you may have been seeing is that the tests input the -1 first. Perhaps your script handled that in a different way than what was expected. It’s on my list to change that to a 0 or 1 instead of a negative number.

The (es)? regex on the 8th test means that the es is optional - so you can use guess or guesses in the message and both should pass.

Ok, thank you very much for your quick response and your explanation. I did not read the test code extensively I confess. The way I set the input test for int, my script simply refuses integers below zero as the number to guess is supposed to be an positive integer (but I did not specified a limit above 1000) : I mechanically reproduced the regex technique to test if the input was an integer (as in former projects : $NUMBER =~ ^[0-9]+$ ) rather than an “arithmetic” test (in fact I wondered at some point if was necessary to set inf/sup limits but as there was no specific instruction I supposed it would not be an issue). I think I’m not the only one who proceeded that way.

Still don’t understand why sometimes the 8th test didn’t pass. But it did, eventually.

Anyway, this course was very pleasant !

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.