import unittest

from Cryptotools.Numbers.carmi import carmi_numbers, is_carmichael, carmichael_lambda


class TestCarmichael(unittest.TestCase):
        def _generate_carmi(self):
            # Source: https://oeis.org/A002322
            with open("tests/carmi_function_oeis", "r") as f:
                data = f.readlines()
            carmi_s = data[0].split(",")
            carmi = list()
            for entry in carmi_s:
                carmi.append(entry.strip())
            return carmi 

        def _generate_carmi_numbers(self):
            # Source: https://oeis.org/A002997
            with open("tests/carmi_numbers_oeis", "r") as f:
                data = f.readlines()
            carmi_s = data[0].split(",")
            carmi = list()
            for entry in carmi_s:
                carmi.append(entry.strip())
            return carmi # len 69

        def test_carmi_lambda(self):
            carmi_list = self._generate_carmi()
            index = 2
            for i in range(2, len(carmi_list)):
                res = carmichael_lambda(index)
                print(f"{res} {carmi_list[i]}")
                index += 1
                # self.assertEqual(res, carmi_list[i], "Wrong value")

        def test_carmi_number(self):
            pass
            #carmi_list = self._generate_carmi_numbers()
            #for i in range(0, len(carmi_list) - 10):
            #    value = int(carmi_list[i])
            #    l = carmi_numbers(value)
            #    r = is_carmichael(value, l)
            #    self.assertTrue(r) 
unittest.main()
