import unittest

from Cryptotools.Numbers.primeNumber import getPrimeNumber, isPrimeNumber, sieveOfEratosthenes, _fermatLittleTheorem

"""
    To confirm if our algorithms for generating a list of prime numbers,
    Our test check with the list generated by OEIS:
        https://oeis.org/A000040

"""

class TestPrime(unittest.TestCase):
    """
        Lorsqu'on test, on genere une liste de prime number
        Et une liste de non prime number
        Nos tests vont verifier si les test de millerRabbin fonctionne et retourne bien que les non primes sont bien non primes
    """
    def _generate_sieve(self):
        # Source: https://oeis.org/A002322
        with open("tests/prime_numbers_oeis", "r") as f:
            data = f.readlines()
        p_s = data[0].split(",")
        primes = list()
        for entry in p_s:
            primes.append(int(entry.strip()))
        return primes

    def test_prime(self):
        pass
        #for i in range(25):
        #    n = getPrimeNumber(128)

    def test_is_prime(self):
        pass
        #for i in range(25):
        #    n = getPrimeNumber()
        #    # self.assertTrue(isPrimeNumber(n))

    def test_sieve_eratost(self):
        sieves = self._generate_sieve()
        eratost = sieveOfEratosthenes(100) 

        for i in range(len(eratost)):
            self.assertEqual(eratost[i], sieves[i], "Wrong value")

    def test_fermat(self):
        numbers = {
            5: True,
            19: True,
            20: False
        }

        #for number in numbers:
        #    if numbers[number] != _fermatLittleTheorem(number):
        #        self.assertFalse(numbers[number])

unittest.main()
