Example #1
0
    def test_prime_factor_calculation(self):
        prime = PrimeNumbers()
        var = 13195
        prime.calc_all_prime_factors(var)

        self.assertEqual(prime.last_prime_factor[0], 5)
        self.assertEqual(prime.last_prime_factor[1], 7)
        self.assertEqual(prime.last_prime_factor[2], 13)
        self.assertEqual(prime.last_prime_factor[3], 29)
Example #2
0
    def test_file_handling(self):
        # Generate data to file
        prime = PrimeNumbers()
        var = 10
        prime.calc_all_prime_factors(var)

        # Init data from file
        prime = PrimeNumbers()
        self.assertEqual(prime.primes[0], 2)
        self.assertEqual(prime.primes[1], 3)
        self.assertEqual(prime.primes[2], 5)
        self.assertEqual(prime.primes[3], 7)
Example #3
0
from prime_numbers import PrimeNumbers
"""
Main program
"""
if __name__ == '__main__':
    try:
        # Init prime number class (Read calculated prime numbers from file)
        prime = PrimeNumbers()

        # Ask value for prime factor calculation
        var = int(input("Give me the number:"))

        # Set result file
        prime.set_res_file('res.txt')

        # Calculate all prime factors for a number defined by user
        prime.calc_all_prime_factors(var)
    except Exception as e:
        print(str(e))