mirror of
https://github.com/kuhyx/WUT_Computer_Science.git
synced 2026-11-21 04:52:24 +01:00
HUSARIA
This commit is contained in:
parent
adbfefcc1f
commit
3c639c6b9c
0
__init__.py
Normal file
0
__init__.py
Normal file
100000
code/C-100000.csv
Normal file
100000
code/C-100000.csv
Normal file
File diff suppressed because it is too large
Load Diff
100000
code/P-100000.csv
Normal file
100000
code/P-100000.csv
Normal file
File diff suppressed because it is too large
Load Diff
0
code/__init__.py
Normal file
0
code/__init__.py
Normal file
51
code/conftest.py
Normal file
51
code/conftest.py
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
import pandas as pd
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from .project import sieve_of_eratosthenes
|
||||||
|
|
||||||
|
|
||||||
|
def pytest_addoption(parser):
|
||||||
|
parser.addoption(
|
||||||
|
"--primes",
|
||||||
|
action="store",
|
||||||
|
default='100',
|
||||||
|
help="Upper bound for primes to test."
|
||||||
|
)
|
||||||
|
parser.addoption(
|
||||||
|
"--composites",
|
||||||
|
action="store",
|
||||||
|
default='100',
|
||||||
|
help="Upper bound for composites to test."
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def pytest_configure(config):
|
||||||
|
pytest.primes = int(config.getoption("--primes"))
|
||||||
|
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]
|
||||||
|
primes = set(df_prime.iloc[:, 1])
|
||||||
|
df_composite = pd.read_csv("C-100000.csv", header=None, delimiter="=")
|
||||||
|
# interpret first oclumns as numbers
|
||||||
|
df_composite = df_composite[df_composite.iloc[:, 0] < pytest.composites]
|
||||||
|
composites = set(df_composite.iloc[:, 0])
|
||||||
|
if metafunc.function.__name__ == 'test_positives':
|
||||||
|
metafunc.parametrize('prime', primes)
|
||||||
|
metafunc.parametrize('primes_obtained', [sieve_of_eratosthenes(max(primes) + 1),])
|
||||||
|
|
||||||
|
if metafunc.function.__name__ == 'test_negatives':
|
||||||
|
metafunc.parametrize('composite', composites)
|
||||||
|
|
||||||
|
metafunc.parametrize('primes_obtained', [sieve_of_eratosthenes(max(composites) + 1),])
|
||||||
@ -1,5 +1,4 @@
|
|||||||
'''Python program to print all Primes Smaller than or equal to N using Sieve of Eratosthenes'''
|
'''Python program to print all Primes Smaller than or equal to N using Sieve of Eratosthenes'''
|
||||||
import time
|
|
||||||
import math
|
import math
|
||||||
|
|
||||||
def sieve_of_eratosthenes(num: int) -> list[int]:
|
def sieve_of_eratosthenes(num: int) -> list[int]:
|
||||||
|
|||||||
8
code/test_main.py
Normal file
8
code/test_main.py
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import pandas as pd
|
||||||
|
|
||||||
|
def test_positives(prime, primes_obtained):
|
||||||
|
assert prime in primes_obtained
|
||||||
|
|
||||||
|
|
||||||
|
def test_negatives(composite, primes_obtained):
|
||||||
|
assert composite not in primes_obtained
|
||||||
Loading…
Reference in New Issue
Block a user