Beispiel #1
0
    def test_timing():
        """ Waits for wait_seconds seconds and checks that the correct time is reported """
        import time
        import io
        from contextlib import redirect_stdout
        wait_seconds = 2
        wrapped_function = timer_decorator.wrap(time.sleep)

        file_handle = io.StringIO()
        with redirect_stdout(file_handle):
            wrapped_function(wait_seconds)
        caught_message = file_handle.getvalue()
        is_correct_message = caught_message.startswith(
            "Total running time was {0}.0".format(wait_seconds))
        assert is_correct_message, "Incorrect message, got {0}".format(
            caught_message)
Beispiel #2
0
def run_main():
    """ Run the exercise as stated on the Euler website and wrapped in a timer"""
    from src.tools import timer_decorator
    wrapped_function = timer_decorator.wrap(sum_of_3_5_multiples)
    return wrapped_function(1000)
Beispiel #3
0
 def test_return_value():
     """ Tests that the correct return value is still returned"""
     wrapped_function = timer_decorator.wrap(lambda: 42)
     assert wrapped_function() == 42
Beispiel #4
0
def run_main():
    """ Run the exercise as stated on the Euler website and wrapped in a timer"""
    from src.tools import timer_decorator
    wrapped_function = timer_decorator.wrap(sum_of_even_fibonacci_numbers)
    return wrapped_function(4000000)
Beispiel #5
0
def run_main():
    """ Run the exercise as stated on the Euler website and wrapped in a timer"""
    from src.tools import timer_decorator
    wrapped_function = timer_decorator.wrap(find_palindrome_product)
    return wrapped_function(99, 999)
Beispiel #6
0
def run_main():
    """ Run the exercise as stated on the Euler website and wrapped in a timer"""
    from src.tools import timer_decorator
    wrapped_function = timer_decorator.wrap(get_prime_no)
    return wrapped_function(10001)
Beispiel #7
0
def run_main():
    """ Run the exercise as stated on the Euler website and wrapped in a timer"""
    from src.tools import timer_decorator
    wrapped_function = timer_decorator.wrap(solve_exercise)
    return wrapped_function(600851475143)
Beispiel #8
0
def run_main():
    """ Run the exercise as stated on the Euler website and wrapped in a timer"""
    from src.tools import timer_decorator
    wrapped_function = timer_decorator.wrap(find_smallest_multiple)
    return wrapped_function(20)