mirror of
https://github.com/kuhyx/WUT_Computer_Science.git
synced 2026-07-06 17:43:03 +02:00
important
This commit is contained in:
parent
3c639c6b9c
commit
281cbf5ea8
@ -99997,4 +99997,4 @@
|
|||||||
110484 = 2 * 2 * 3 * 3 * 3 * 3 * 11 * 31
|
110484 = 2 * 2 * 3 * 3 * 3 * 3 * 11 * 31
|
||||||
110485 = 5 * 19 * 1163
|
110485 = 5 * 19 * 1163
|
||||||
110486 = 2 * 55243
|
110486 = 2 * 55243
|
||||||
110487 = 3 * 13 * 2833
|
110487 = 3 * 13 * 2833
|
||||||
|
Can't render this file because it is too large.
|
@ -24,15 +24,6 @@ def pytest_configure(config):
|
|||||||
pytest.composites = int(config.getoption("--composites"))
|
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):
|
def pytest_generate_tests(metafunc):
|
||||||
df_prime = pd.read_csv("P-100000.csv", header=None)
|
df_prime = pd.read_csv("P-100000.csv", header=None)
|
||||||
df_prime = df_prime[df_prime.iloc[:, 1] < pytest.primes]
|
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('prime', primes)
|
||||||
metafunc.parametrize('primes_obtained', [sieve_of_eratosthenes(max(primes) + 1),])
|
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('composite', composites)
|
||||||
|
|
||||||
metafunc.parametrize('primes_obtained', [sieve_of_eratosthenes(max(composites) + 1),])
|
metafunc.parametrize('primes_obtained', [sieve_of_eratosthenes(max(composites) + 1),])
|
||||||
|
|||||||
@ -10,6 +10,8 @@ def sieve_of_eratosthenes(num: int) -> list[int]:
|
|||||||
Returns:
|
Returns:
|
||||||
list[int]: List of prime numbers
|
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
|
# boolean list to store if a number is prime or not
|
||||||
prime = [True] * (num+1)
|
prime = [True] * (num+1)
|
||||||
p = 2 # starting prime number
|
p = 2 # starting prime number
|
||||||
@ -41,8 +43,5 @@ def print_sieve(num: int) -> None:
|
|||||||
# Driver code
|
# Driver code
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
num = int(input("Enter a number: "))
|
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(f"Following are the prime numbers smaller than or equal to {num}")
|
||||||
print_sieve(num)
|
print_sieve(num)
|
||||||
@ -1,8 +1,15 @@
|
|||||||
import pandas as pd
|
import pandas as pd
|
||||||
|
import pytest
|
||||||
|
from .project import sieve_of_eratosthenes
|
||||||
|
|
||||||
def test_positives(prime, primes_obtained):
|
def test_positives(prime, primes_obtained):
|
||||||
assert prime in primes_obtained
|
assert prime in primes_obtained
|
||||||
|
|
||||||
|
|
||||||
def test_negatives(composite, primes_obtained):
|
def test_composites(composite, primes_obtained):
|
||||||
assert composite not in primes_obtained
|
assert composite not in primes_obtained
|
||||||
|
|
||||||
|
|
||||||
|
def test_negatives():
|
||||||
|
with pytest.raises(ValueError):
|
||||||
|
sieve_of_eratosthenes(-1)
|
||||||
Loading…
Reference in New Issue
Block a user