def test_primes_to_max():
    """test the output of our primes generator"""
    prime = PrimeGenerator()
    assert 2 not in prime.prime_list
    prime_list = prime.primes_to_max(43)
    assert 31 in prime_list
    assert 23 in prime_list
def test_primes_to_max():
    ''' Test the Prime to max method'''

    pr = PrimeGenerator()
    assert pr.primes_to_max(6) == [2, 3, 5]
    assert pr.primes_to_max(30) == [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
    assert pr.primes_to_max(50) == [
        2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47
    ]
示例#3
0
def main():
    """Test program that uses the prime_generator module to print the first 500 prime numbers"""

    print "\nPrints out the first 500 prime numbers:\n"

    prime_generator = PrimeGenerator()
    for i in range(50):
        primes = prime_generator.generate(10)
        for j in range(10):
            print "{0:8d}".format(primes[j]),
        print
示例#4
0
def main():
    """contain a main function that call a method defined in that
    module that returns the list of primes, and finally it should print
    them out."""
    user_input = int(
        input("Enter an integer which is greater than 1, we will" +
              " print out all of prime numbers: "))

    while user_input <= 1:
        print("Invalid input, please enter again: ")
        user_input = int(input(""))
    else:
        prime_num = PrimeGenerator()
        prime_list = prime_num.primes_to_max(user_input)

        print(prime_list)
示例#5
0
def main():
    num = int(
        input("enter an integer and you will get all the prime numbers" +
              "from 2 to that integer: "))
    start = time.perf_counter()
    list_of_primes = PrimeGenerator(num).primes_to_max()
    end = time.perf_counter()
    time_cost = end - start
    print(list_of_primes)
    print("time cost is", time_cost)
    def test_keeps_memory_of_primes(self):
        pgen = PrimeGenerator()
        expect(pgen.memory).to(equal([]))

        pgen.generate(2)
        expect(pgen.memory).to(equal([2, 3]))

        pgen.generate(5)
        expect(pgen.memory).to(equal([2, 3, 5, 7, 11]))

        pgen.generate(4)
        expect(pgen.memory).to(equal([2, 3, 5, 7, 11]))
示例#7
0
def test_primes_to_max():
    p = PrimeGenerator()
    # test the list within primes smaller or equal to 100
    p_100 = p.primes_to_max(100)
    assert p_100 == [
        2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67,
        71, 73, 79, 83, 89, 97
    ]
    assert 10 not in p_100
    # test the list within primes smaller or equal to 1000
    p_1000 = p.primes_to_max(1000)
    assert 877 in p_1000
    assert 409 in p_1000
    assert 555 not in p_1000
    # test the list within primes smaller or equal to 3966
    p_3966 = p.primes_to_max(3966)
    assert 991 in p_3966
    assert 3119 in p_3966
    # even 3967 is a prime, it is out of index of 3966 so it shouldn't in it
    assert 3967 not in p_3966
    assert 2688 not in p_3966
示例#8
0
def test_primes_to_max():
    """test the output prime list with a given argument value"""
    generator = PrimeGenerator()
    prime_list_10 = [2, 3, 5, 7]
    assert generator.primes_to_max(10) == prime_list_10
    prime_list_20 = [2, 3, 5, 7, 11, 13, 17, 19]
    generator_2 = PrimeGenerator()
    assert generator_2.primes_to_max(20) == prime_list_20
示例#9
0
def test_primes_to_max():
    """Test primes_to_max method"""
    prime_g = PrimeGenerator()
    assert prime_g.primes_to_max(100) == [
        2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67,
        71, 73, 79, 83, 89, 97
    ]

    prime_g = PrimeGenerator()
    assert prime_g.primes_to_max(2) == [2]
 def test_can_make_nth_prime(self):
     pgen = PrimeGenerator()
     expect(pgen.generate(2)).to(equal(3))
     expect(pgen.generate(5)).to(equal(11))
示例#11
0
def main():

    number = int(input("Enter a number: \n"))
    prime_list = PrimeGenerator()

    print(prime_list.primes_to_max(number))
示例#12
0
def test_primes_to_max():
    assert PrimeGenerator().primes_to_max(30)[-1] == 29
    assert PrimeGenerator().primes_to_max(30)[0] == 2
    assert PrimeGenerator().primes_to_max(10) == [2, 3, 5, 7]
    assert PrimeGenerator().primes_to_max(97)[-1] == 97
示例#13
0
def test_constructor():
    """Test the constructor"""
    prime_g = PrimeGenerator()
    assert prime_g.composed_set == set()
    assert prime_g.prime_list == []
示例#14
0
def main():
    max = int(input("Enter the limit: "))
    pg = PrimeGenerator()
    prime_list = pg.primes_to_max(max)
    print(prime_list)
示例#15
0
def main():
    """call PrimeGeneartor constructor and generate_prime function"""
    generator = PrimeGenerator()
    generate_prime(generator)
def main():

    pl = PrimeGenerator(TEST_NUMBER)
    primes = pl.primes_to_max()
    print(primes)
 def test_can_check_if_prime(self):
     pgen = PrimeGenerator()
     expect(pgen.check(1)).to(be_false)
     expect(pgen.check(2)).to(be_true)
     expect(pgen.check(5)).to(be_true)
     expect(pgen.check(12)).to(be_false)
示例#18
0
def main():
    end = int(input("Prime numbers up to: "))
    print(PrimeGenerator().primes_to_max(end))
示例#19
0
def main():
    """print all primes in range"""
    prime = PrimeGenerator()
    max_range = int(input("Please enter the larget number:\n"))
    prime_list = prime.primes_to_max(max_range)
    print("Prime are:\n", prime_list)
示例#20
0
def test_primes_to_max():
    primes_list = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]
    pg = PrimeGenerator()
    generated_list = pg.primes_to_max(50)
    assert all(elem in primes_list for elem in generated_list)