I was dong hackerrank test. My code provides required output by providing input but test shows it is a wrong answer. The link for test is https://www.hackerrank.com/contests/fullstack/challenges/testrun
Input Format
1 2 3
Output Format
2 3 7
Sample Input
1 9 9
Sample Output
? ? ?
Explanation
function processData(input) {
//Enter your code here
var number;
var main = "";
const aray = input.split(' ').map(Number)
for (var i = 0; i < aray.length; i++) {
if (i === aray.length-1 && aray.length>1) {
if (aray[i]*2 + 1 >= 9) {
main += '?';
}
else {
main += aray[i]*2 + 1
}
}
else {
if (aray[i+1] >= 9) {
main += '?';
main += ' '
}
else {
main += aray[i] + 1;
main += ' '
}
}
}
console.log(main);
}
process.stdin.resume();
process.stdin.setEncoding("ascii");
_input = '';
process.stdin.on("data", function (input) {
_input += input;
});
process.stdin.on("end", function () {
processData(_input);
});
How do I create test cases? If you know then please mention the mistake. Thanks
If you just want to test a bunch of inputs, then write a bunch of function calls with different types of input.
Example:
If you want to automate providing input into your application, then something like robotjs might be useful.
If you're looking for a full on testing framework, then you can use mocha and chai. Here's an article on how to use them with node.