Last active
August 4, 2019 13:04
-
-
Save obestwalter/14eb9d6176f0253125215558cbf87427 to your computer and use it in GitHub Desktop.
Solution for Euler 1 one the pytest way
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Solve https://projecteuler.net/problem=1 the pytest way | |
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. | |
Find the sum of all the multiples of 3 or 5 below 1000. | |
""" | |
import pytest | |
@pytest.fixture(name="key", scope="session") | |
def euler_cache_provider(request): | |
key = "e1" | |
request.config.cache.set(key, 0) | |
yield key | |
result = request.config.cache.get(key, None) | |
assert 0, result | |
@pytest.mark.parametrize("i", list(range(1, 1000))) | |
def test_euler_1(i, request, key): | |
result = request.config.cache.get(key, 0) | |
if i % 3 == 0 or i % 5 == 0: | |
request.config.cache.set(key, result + i) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is the expected result - 999 green tests but at teardown is an assertion error that prints out the result. I know. Stupid :)