import unittest

from Cryptotools.Numbers.coprime import phi

class TestPhi(unittest.TestCase):
    def _generate_phi(self):
        # Source: https://oeis.org/A000010
        with open("tests/phi_oeis", "r") as f:
            data = f.readlines()
        phi_s = data[0].split(",")
        phi = list()
        for entry in phi_s:
            phi.append(int(entry.strip()))
        return phi # len 69

    def test_phi(self):
        phi_list = self._generate_phi()
        index = 0
        for i in range(1, len(phi_list) + 1):
            res = phi(i)
            # print(f"{i} {res}")
            value = phi_list[index]
            # print(f"{res}: {value}")
            self.assertEqual(res, value, "Wrong value")
            index += 1
unittest.main()
