Bug - 13_caesar: Test results appear correct but Fail
kgroening05 opened this issue · 4 comments
Complete the following REQUIRED checkboxes:
- I have thoroughly read and understand The Odin Project Contributing Guide
- The title of this issue follows the
Bug - location of bug: brief description of bug
format, e.g.Bug - Exercises: File type incorrect for all test files
The following checkbox is OPTIONAL:
- I would like to be assigned this issue to work on it
1. Description of the Bug:
Running the tests on my code results in results that seem to pass but are counted as fail.
2. How To Reproduce:
This is my code for the project:
const caesar = function(string, shiftValue) {
let encodedString = "";
for (let index = 0; index < string.length + 1; index++) {
let letterUnicode = string.charCodeAt(index);
if (letterUnicode >= 65 && letterUnicode <= 90){ // Capital letters
letterUnicode += shiftValue;
while (letterUnicode >90){ // Deal with overlapping into other unicodes
letterUnicode -= 26;
}
while (letterUnicode <65){
letterUnicode += 26;
}
}
else if(letterUnicode >= 97 && letterUnicode <= 122){ // Lowercase letters
letterUnicode += shiftValue;
while (letterUnicode > 122){ // Deal with overlapping into other unicodes
letterUnicode -= 26;
}
while (letterUnicode < 97){
letterUnicode += 26;
}
}
encodedString += String.fromCharCode(letterUnicode);
}
return encodedString;
};
3. Expected Behavior:
The tests results for all of the tests appear correct, but they all fail. I haven't modified the .spec.js file in any way other than removing .skip from all the tests.
Haven't seen this kind of issue with the previous exercises.
4. Desktop/Device:
- Device: Lenovo Laptop
- OS: Windows 10
- Node version: v18.12.1
- Jest version: 8.19.2
5. Additional Information:
I'm wondering if there's some quirk to the fromCharCode method. Maybe there are some invisible characters being added. Or perhaps the terminal is hiding something and making the results appear identical when they are actually different in some way.
I'm wondering if there's some quirk to the fromCharCode method. Maybe there are some invisible characters being added. Or perhaps the terminal is hiding something and making the results appear identical when they are actually different in some way.
After spending way too much time trying to figure this out and getting nowhere because I was doing it purely via the console (which lies) @nguyenlekhtn pointed out on Discord that your code also inserts a null
character, so the tests are successfully failing