Mocha test on simple code fails when for no apparent reason





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















This is a sort of an online programming test. The system allows you to write a solution to problems and checks it against it's (the platform's internal) unit tests.



Here is the summary of the problem:




To write a function that takes 2 params (x, y).



If x is greater than y, it returns an array of even numbers
between x and y.



If x is lesser than y, it returns an array of odd numbers between
x and y.



If x and y are equal, or if the input is invalid/not integers, it
returns an empty array.
The resulting array is exclusive of x and y
in each case.



For instance, if x, y are integers 10, 2, the function would return
all the even numbers between 2 and 10 i.e [4, 6, 8].




Here is my code:



const numGame = (x, y) => {
let result = ;
if (!Number.isInteger(x) || !Number.isInteger(y)) {
return result;
}
if (x > y) {
for(let i = y + 1; i < x; i++)
if(i%2 == 0) result.push(i);
}
if (x < y) {
for(let i = x + 1; i < y; i++) {
if(i%2 == 1 || i%2 == -1) result.push(i);
}
}

return result;
}


Here are my own tests that pass easily:



describe('Challenge', function() {
it('should return the right array', function() {
assert.deepEqual(numGame(2,12), [3, 5, 7, 9, 11]);
assert.deepEqual(numGame(12, 2), [4, 6, 8, 10]);
assert.deepEqual(numGame(-6, 12), [-5, -3, -1, 1, 3, 5, 7, 9, 11]);
assert.deepEqual(numGame(12, -4), [-2, 0, 2, 4, 6, 8, 10]);
assert.deepEqual(numGame(0,0), );
});
});


My tests above pass, but when I submit my code, it fails the internal tests and returns the following:



should return the right array
expected [ Array(9) ] to deeply equal [ Array(11) ]


The error seems strange. There's no way to see the code my solution is tested against so it's really frustrating. Please, review my solution to see if there are any edge cases that it's not handling, and maybe provide a better solution/algorithm.



I would also like to know if there's a chance that the platform's internal test might be wrong in some way? Thanks!










share|improve this question




















  • 1





    You need to provide more details about the specification. 1) "If y is greater than y" is probably a mistake, and should read "if x is greater than y". 2) Are the limits inclusive or exclusive? In other words, is "between 1 and 3" equal to [1, 2, 3] or [2]. 3) What happens when x == y?

    – Sami Hult
    Nov 25 '18 at 7:14













  • @SamiHult, thanks for pointing out the blanks, I just edited the the question. Can you please take a look now?

    – Mudi
    Nov 25 '18 at 7:44











  • It seems to me that the code works as expected. The feedback from the testing machine suggests that either you have misread some of the instructions (array lengths 9 vs. 11 could mean that the limits are inclusive, after all) or that the test case is on the remote machine is, in fact, faulty. If you are sure that you understood the instructions correctly, I suggest that you raise a concern about the validity of the test.

    – Sami Hult
    Nov 25 '18 at 7:59











  • @SamiHult, the instructions were clear enough, even sample tests provided by the platform indicates that. It turns out that the platform's test is in fact wrong. I edited the code to include x and y, and the test passed. I always thought I was a shitty developer!

    – Mudi
    Nov 25 '18 at 8:32


















0















This is a sort of an online programming test. The system allows you to write a solution to problems and checks it against it's (the platform's internal) unit tests.



Here is the summary of the problem:




To write a function that takes 2 params (x, y).



If x is greater than y, it returns an array of even numbers
between x and y.



If x is lesser than y, it returns an array of odd numbers between
x and y.



If x and y are equal, or if the input is invalid/not integers, it
returns an empty array.
The resulting array is exclusive of x and y
in each case.



For instance, if x, y are integers 10, 2, the function would return
all the even numbers between 2 and 10 i.e [4, 6, 8].




Here is my code:



const numGame = (x, y) => {
let result = ;
if (!Number.isInteger(x) || !Number.isInteger(y)) {
return result;
}
if (x > y) {
for(let i = y + 1; i < x; i++)
if(i%2 == 0) result.push(i);
}
if (x < y) {
for(let i = x + 1; i < y; i++) {
if(i%2 == 1 || i%2 == -1) result.push(i);
}
}

return result;
}


Here are my own tests that pass easily:



describe('Challenge', function() {
it('should return the right array', function() {
assert.deepEqual(numGame(2,12), [3, 5, 7, 9, 11]);
assert.deepEqual(numGame(12, 2), [4, 6, 8, 10]);
assert.deepEqual(numGame(-6, 12), [-5, -3, -1, 1, 3, 5, 7, 9, 11]);
assert.deepEqual(numGame(12, -4), [-2, 0, 2, 4, 6, 8, 10]);
assert.deepEqual(numGame(0,0), );
});
});


My tests above pass, but when I submit my code, it fails the internal tests and returns the following:



should return the right array
expected [ Array(9) ] to deeply equal [ Array(11) ]


The error seems strange. There's no way to see the code my solution is tested against so it's really frustrating. Please, review my solution to see if there are any edge cases that it's not handling, and maybe provide a better solution/algorithm.



I would also like to know if there's a chance that the platform's internal test might be wrong in some way? Thanks!










share|improve this question




















  • 1





    You need to provide more details about the specification. 1) "If y is greater than y" is probably a mistake, and should read "if x is greater than y". 2) Are the limits inclusive or exclusive? In other words, is "between 1 and 3" equal to [1, 2, 3] or [2]. 3) What happens when x == y?

    – Sami Hult
    Nov 25 '18 at 7:14













  • @SamiHult, thanks for pointing out the blanks, I just edited the the question. Can you please take a look now?

    – Mudi
    Nov 25 '18 at 7:44











  • It seems to me that the code works as expected. The feedback from the testing machine suggests that either you have misread some of the instructions (array lengths 9 vs. 11 could mean that the limits are inclusive, after all) or that the test case is on the remote machine is, in fact, faulty. If you are sure that you understood the instructions correctly, I suggest that you raise a concern about the validity of the test.

    – Sami Hult
    Nov 25 '18 at 7:59











  • @SamiHult, the instructions were clear enough, even sample tests provided by the platform indicates that. It turns out that the platform's test is in fact wrong. I edited the code to include x and y, and the test passed. I always thought I was a shitty developer!

    – Mudi
    Nov 25 '18 at 8:32














0












0








0








This is a sort of an online programming test. The system allows you to write a solution to problems and checks it against it's (the platform's internal) unit tests.



Here is the summary of the problem:




To write a function that takes 2 params (x, y).



If x is greater than y, it returns an array of even numbers
between x and y.



If x is lesser than y, it returns an array of odd numbers between
x and y.



If x and y are equal, or if the input is invalid/not integers, it
returns an empty array.
The resulting array is exclusive of x and y
in each case.



For instance, if x, y are integers 10, 2, the function would return
all the even numbers between 2 and 10 i.e [4, 6, 8].




Here is my code:



const numGame = (x, y) => {
let result = ;
if (!Number.isInteger(x) || !Number.isInteger(y)) {
return result;
}
if (x > y) {
for(let i = y + 1; i < x; i++)
if(i%2 == 0) result.push(i);
}
if (x < y) {
for(let i = x + 1; i < y; i++) {
if(i%2 == 1 || i%2 == -1) result.push(i);
}
}

return result;
}


Here are my own tests that pass easily:



describe('Challenge', function() {
it('should return the right array', function() {
assert.deepEqual(numGame(2,12), [3, 5, 7, 9, 11]);
assert.deepEqual(numGame(12, 2), [4, 6, 8, 10]);
assert.deepEqual(numGame(-6, 12), [-5, -3, -1, 1, 3, 5, 7, 9, 11]);
assert.deepEqual(numGame(12, -4), [-2, 0, 2, 4, 6, 8, 10]);
assert.deepEqual(numGame(0,0), );
});
});


My tests above pass, but when I submit my code, it fails the internal tests and returns the following:



should return the right array
expected [ Array(9) ] to deeply equal [ Array(11) ]


The error seems strange. There's no way to see the code my solution is tested against so it's really frustrating. Please, review my solution to see if there are any edge cases that it's not handling, and maybe provide a better solution/algorithm.



I would also like to know if there's a chance that the platform's internal test might be wrong in some way? Thanks!










share|improve this question
















This is a sort of an online programming test. The system allows you to write a solution to problems and checks it against it's (the platform's internal) unit tests.



Here is the summary of the problem:




To write a function that takes 2 params (x, y).



If x is greater than y, it returns an array of even numbers
between x and y.



If x is lesser than y, it returns an array of odd numbers between
x and y.



If x and y are equal, or if the input is invalid/not integers, it
returns an empty array.
The resulting array is exclusive of x and y
in each case.



For instance, if x, y are integers 10, 2, the function would return
all the even numbers between 2 and 10 i.e [4, 6, 8].




Here is my code:



const numGame = (x, y) => {
let result = ;
if (!Number.isInteger(x) || !Number.isInteger(y)) {
return result;
}
if (x > y) {
for(let i = y + 1; i < x; i++)
if(i%2 == 0) result.push(i);
}
if (x < y) {
for(let i = x + 1; i < y; i++) {
if(i%2 == 1 || i%2 == -1) result.push(i);
}
}

return result;
}


Here are my own tests that pass easily:



describe('Challenge', function() {
it('should return the right array', function() {
assert.deepEqual(numGame(2,12), [3, 5, 7, 9, 11]);
assert.deepEqual(numGame(12, 2), [4, 6, 8, 10]);
assert.deepEqual(numGame(-6, 12), [-5, -3, -1, 1, 3, 5, 7, 9, 11]);
assert.deepEqual(numGame(12, -4), [-2, 0, 2, 4, 6, 8, 10]);
assert.deepEqual(numGame(0,0), );
});
});


My tests above pass, but when I submit my code, it fails the internal tests and returns the following:



should return the right array
expected [ Array(9) ] to deeply equal [ Array(11) ]


The error seems strange. There's no way to see the code my solution is tested against so it's really frustrating. Please, review my solution to see if there are any edge cases that it's not handling, and maybe provide a better solution/algorithm.



I would also like to know if there's a chance that the platform's internal test might be wrong in some way? Thanks!







javascript arrays node.js unit-testing mocha






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 25 '18 at 9:41









Yashwardhan Pauranik

2,24311731




2,24311731










asked Nov 25 '18 at 7:03









MudiMudi

85




85








  • 1





    You need to provide more details about the specification. 1) "If y is greater than y" is probably a mistake, and should read "if x is greater than y". 2) Are the limits inclusive or exclusive? In other words, is "between 1 and 3" equal to [1, 2, 3] or [2]. 3) What happens when x == y?

    – Sami Hult
    Nov 25 '18 at 7:14













  • @SamiHult, thanks for pointing out the blanks, I just edited the the question. Can you please take a look now?

    – Mudi
    Nov 25 '18 at 7:44











  • It seems to me that the code works as expected. The feedback from the testing machine suggests that either you have misread some of the instructions (array lengths 9 vs. 11 could mean that the limits are inclusive, after all) or that the test case is on the remote machine is, in fact, faulty. If you are sure that you understood the instructions correctly, I suggest that you raise a concern about the validity of the test.

    – Sami Hult
    Nov 25 '18 at 7:59











  • @SamiHult, the instructions were clear enough, even sample tests provided by the platform indicates that. It turns out that the platform's test is in fact wrong. I edited the code to include x and y, and the test passed. I always thought I was a shitty developer!

    – Mudi
    Nov 25 '18 at 8:32














  • 1





    You need to provide more details about the specification. 1) "If y is greater than y" is probably a mistake, and should read "if x is greater than y". 2) Are the limits inclusive or exclusive? In other words, is "between 1 and 3" equal to [1, 2, 3] or [2]. 3) What happens when x == y?

    – Sami Hult
    Nov 25 '18 at 7:14













  • @SamiHult, thanks for pointing out the blanks, I just edited the the question. Can you please take a look now?

    – Mudi
    Nov 25 '18 at 7:44











  • It seems to me that the code works as expected. The feedback from the testing machine suggests that either you have misread some of the instructions (array lengths 9 vs. 11 could mean that the limits are inclusive, after all) or that the test case is on the remote machine is, in fact, faulty. If you are sure that you understood the instructions correctly, I suggest that you raise a concern about the validity of the test.

    – Sami Hult
    Nov 25 '18 at 7:59











  • @SamiHult, the instructions were clear enough, even sample tests provided by the platform indicates that. It turns out that the platform's test is in fact wrong. I edited the code to include x and y, and the test passed. I always thought I was a shitty developer!

    – Mudi
    Nov 25 '18 at 8:32








1




1





You need to provide more details about the specification. 1) "If y is greater than y" is probably a mistake, and should read "if x is greater than y". 2) Are the limits inclusive or exclusive? In other words, is "between 1 and 3" equal to [1, 2, 3] or [2]. 3) What happens when x == y?

– Sami Hult
Nov 25 '18 at 7:14







You need to provide more details about the specification. 1) "If y is greater than y" is probably a mistake, and should read "if x is greater than y". 2) Are the limits inclusive or exclusive? In other words, is "between 1 and 3" equal to [1, 2, 3] or [2]. 3) What happens when x == y?

– Sami Hult
Nov 25 '18 at 7:14















@SamiHult, thanks for pointing out the blanks, I just edited the the question. Can you please take a look now?

– Mudi
Nov 25 '18 at 7:44





@SamiHult, thanks for pointing out the blanks, I just edited the the question. Can you please take a look now?

– Mudi
Nov 25 '18 at 7:44













It seems to me that the code works as expected. The feedback from the testing machine suggests that either you have misread some of the instructions (array lengths 9 vs. 11 could mean that the limits are inclusive, after all) or that the test case is on the remote machine is, in fact, faulty. If you are sure that you understood the instructions correctly, I suggest that you raise a concern about the validity of the test.

– Sami Hult
Nov 25 '18 at 7:59





It seems to me that the code works as expected. The feedback from the testing machine suggests that either you have misread some of the instructions (array lengths 9 vs. 11 could mean that the limits are inclusive, after all) or that the test case is on the remote machine is, in fact, faulty. If you are sure that you understood the instructions correctly, I suggest that you raise a concern about the validity of the test.

– Sami Hult
Nov 25 '18 at 7:59













@SamiHult, the instructions were clear enough, even sample tests provided by the platform indicates that. It turns out that the platform's test is in fact wrong. I edited the code to include x and y, and the test passed. I always thought I was a shitty developer!

– Mudi
Nov 25 '18 at 8:32





@SamiHult, the instructions were clear enough, even sample tests provided by the platform indicates that. It turns out that the platform's test is in fact wrong. I edited the code to include x and y, and the test passed. I always thought I was a shitty developer!

– Mudi
Nov 25 '18 at 8:32












1 Answer
1






active

oldest

votes


















0














It turns out that the platform's test against which my code is tested, is in fact wrong. I edited the code to include x and y, and the test passed.






share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53465383%2fmocha-test-on-simple-code-fails-when-for-no-apparent-reason%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    It turns out that the platform's test against which my code is tested, is in fact wrong. I edited the code to include x and y, and the test passed.






    share|improve this answer




























      0














      It turns out that the platform's test against which my code is tested, is in fact wrong. I edited the code to include x and y, and the test passed.






      share|improve this answer


























        0












        0








        0







        It turns out that the platform's test against which my code is tested, is in fact wrong. I edited the code to include x and y, and the test passed.






        share|improve this answer













        It turns out that the platform's test against which my code is tested, is in fact wrong. I edited the code to include x and y, and the test passed.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 25 '18 at 8:36









        MudiMudi

        85




        85
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53465383%2fmocha-test-on-simple-code-fails-when-for-no-apparent-reason%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            Xamarin.form Move up view when keyboard appear

            Post-Redirect-Get with Spring WebFlux and Thymeleaf

            Anylogic : not able to use stopDelay()