Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

175
Vistas
How to set a time limit for a program to execute?

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)).

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda