I am currently writing tests for a sort of Diagnostic test for a friend. I did a Python version of it, and what I want to do is to stop the test if the problem is taking too long. For example in Python this is how I did it:
@timeout_decorator.timeout(5)
def test_intersection_that_will_break_if_solution_is_too_slow(self):
a = [i for i in range(0, 50000)]
b = [i for i in range(0, 50000)]
result = intersection.intersection(a, b)
self.assertEqual(result, a)
In JavaScript, in Chaijs, I have this, but don't know how to stop the execution after a certain period of time. I am not the best at js either or chai, but maybe some sort of setTimeOut?
context('if a = [0,1,2,3...,49999] and b = [0,1,2,3...,49999] ', () => {
it("should return [0,1,2,3...,49999] ", () => {
const a = [];
const b = [];
for (let i = 0; i < 50000; i += 1) {
a.push(i);
b.push(i);
}
result = intersection(a, b);
expect(result).to.eql(a);
})
})
I want to know how to do that in Chai, because when I do the tests for a fibonacci problem, I want to stop the execution if it is taking too long(although I believe that chai/mocha stops the execution after 2000 ms but I still want to encourage my friend to look for a more optimal solution rather than getting the right answer with a red (1193ms)).