important

This commit is contained in:
Normale 2023-01-08 18:57:59 +01:00
parent 3c639c6b9c
commit 281cbf5ea8
4 changed files with 13 additions and 17 deletions

View File

@ -99997,4 +99997,4 @@
110484 = 2 * 2 * 3 * 3 * 3 * 3 * 11 * 31
110485 = 5 * 19 * 1163
110486 = 2 * 55243
110487 = 3 * 13 * 2833
110487 = 3 * 13 * 2833
Can't render this file because it is too large.

View File

@ -24,15 +24,6 @@ def pytest_configure(config):
pytest.composites = int(config.getoption("--composites"))
@pytest.fixture
def primes_obtained():
return set(sieve_of_eratosthenes(pytest.primes + 1))
@pytest.fixture
def composites_obtained():
return set(sieve_of_eratosthenes(pytest.composites + 1))
def pytest_generate_tests(metafunc):
df_prime = pd.read_csv("P-100000.csv", header=None)
df_prime = df_prime[df_prime.iloc[:, 1] < pytest.primes]
@ -45,7 +36,6 @@ def pytest_generate_tests(metafunc):
metafunc.parametrize('prime', primes)
metafunc.parametrize('primes_obtained', [sieve_of_eratosthenes(max(primes) + 1),])
if metafunc.function.__name__ == 'test_negatives':
if metafunc.function.__name__ == 'test_composites':
metafunc.parametrize('composite', composites)
metafunc.parametrize('primes_obtained', [sieve_of_eratosthenes(max(composites) + 1),])

View File

@ -10,6 +10,8 @@ def sieve_of_eratosthenes(num: int) -> list[int]:
Returns:
list[int]: List of prime numbers
"""
if num <= 0:
raise ValueError("Number should not be negative.")
# boolean list to store if a number is prime or not
prime = [True] * (num+1)
p = 2 # starting prime number
@ -41,8 +43,5 @@ def print_sieve(num: int) -> None:
# Driver code
if __name__ == '__main__':
num = int(input("Enter a number: "))
while num < 2:
print("Limit smaller than 2, pick another number")
num = int(input("Enter a number: "))
print(f"Following are the prime numbers smaller than or equal to {num}")
print_sieve(num)

View File

@ -1,8 +1,15 @@
import pandas as pd
import pytest
from .project import sieve_of_eratosthenes
def test_positives(prime, primes_obtained):
assert prime in primes_obtained
def test_negatives(composite, primes_obtained):
assert composite not in primes_obtained
def test_composites(composite, primes_obtained):
assert composite not in primes_obtained
def test_negatives():
with pytest.raises(ValueError):
sieve_of_eratosthenes(-1)