예제 #1
0
 def test_is_prime(self):
     repo = SqlitePrimesRepository()
     for number in range(0, 200):
         try:
             check_fast = repo.is_prime(number)
             check_slow = sympy.isprime(number)
             print(number, check_fast, check_slow)
             self.assertEqual(check_fast, check_slow)
         except NotEnoughPrimesException as e:
             print(e.message)
         except IsLessThan2Exception as e:
             print(e.message)
예제 #2
0
 def test_save(self):
     repo = SqlitePrimesRepository()
     for number in range(0, 200):
         try:
             repo.save(number)
             print(f'Adding number {number}')
         except NotAPrimeException as e:
             print(e.message)
         except PrimeAlreadySavedException as e:
             print(e.message)
         except NotEnoughPrimesException as e:
             print(e.message)
         except IsLessThan2Exception as e:
             print(e.message)
예제 #3
0
#!/usr/bin/python
import sys
import time

from src.repositories.SqlitePrimesRepository import SqlitePrimesRepository, NotAPrimeException, \
    PrimeAlreadySavedException, NotEnoughPrimesException, IsLessThan2Exception
from src.utilities.text_utility import text_out

repo = SqlitePrimesRepository()
upper_limit = 10000000
start_time = time.time()
print(f"Current number of primes found: {repo.count()}")
repo = SqlitePrimesRepository()
for number in range(0, upper_limit):
    try:
        text_out(f'Checking number {number}')
        repo.save(number)
        text_out(f'Adding number {number}')
    except NotAPrimeException as e:
        text_out(e.message)
    except PrimeAlreadySavedException as e:
        text_out(e.message)
    except NotEnoughPrimesException as e:
        text_out(e.message)
    except IsLessThan2Exception as e:
        text_out(e.message)
sys.stdout.write('\n')
print(f"Found {repo.count()} primes in {time.time() - start_time} seconds.")
sys.stdout.write('\n')
repo.close()
예제 #4
0
 def test_count_all_less(self):
     repo = SqlitePrimesRepository()
     number = 1000000
     found = repo.count_all_less(number)
     print(f'Found {found} primes less than {number}')
예제 #5
0
 def test_find_all_less(self):
     repo = SqlitePrimesRepository()
     found = repo.find_all_less(100).fetchall()
     print(len(found))
예제 #6
0
 def test_count(self):
     repo = SqlitePrimesRepository()
     count = repo.count()
     print(f"Found {count} primes.")
     self.assertTrue(count > 0)
     repo.close()
예제 #7
0
 def test_find(self):
     repo = SqlitePrimesRepository()
     prime = repo.find(3)
     self.assertTrue(prime == 3)
     prime = repo.find(4)
     self.assertIsNone(prime)
예제 #8
0
 def test_find_all(self):
     repo = SqlitePrimesRepository()
     primes = repo.find_all()
     self.assertTrue(len(primes) > 0)
예제 #9
0
 def test_init(self):
     repo = SqlitePrimesRepository()
     self.assertTrue(os.path.exists(repo.file))
예제 #10
0
 def __init__(self):
     self.repo = SqlitePrimesRepository()
     self.converter = Converter()