コード例 #1
0
ファイル: mert_unit_tests.py プロジェクト: glogou/tmp_testing
def unit_test_sequence():
    # Do some unit test
    unit_test_get_primes_to_try()
    unit_test_is_this_end_of_tree_leaf()
    unit_test_prime_product_count()

    # generate primes up to target_num,
    target_num = 70
    primes = get_prime_list(target_num)
    print 'num of primes %d'%(len(primes))

    # find the number of prime product with specific factors, and
    # do some cross testing
    all_2_factors_choices = count_number_prime_product_with_2factors(primes, target_num)
    all_3_factors_choices = count_number_prime_product_with_3factors(primes, target_num)
    all_of_1_factors, all_of_2_factors, all_of_3_factors, all_of_4_factors = \
        count_number_prime_product_with_4factors(primes, target_num)

    # verify those result are correct
    assert(all_2_factors_choices == all_of_2_factors)
    assert(all_3_factors_choices == all_of_3_factors)

    begin_list = [1]
    factors_his = [0]* MAX_NUM_FACTORS
    primes = get_prime_list(target_num)
    factors_his, factors_his_cur_n_down = count_number_prime_product_recursive(begin_list, primes, target_num, factors_his)
    print target_num, factors_his, factors_his_cur_n_down

    all_1_factors_comm, all_2_factors_comm, all_3_factors_comm, all_4_factors_comm = get_select_factors(factors_his)

    assert(all_2_factors_comm == all_of_2_factors)
    assert(all_3_factors_comm == all_of_3_factors)
    assert(all_4_factors_comm == all_of_4_factors)
コード例 #2
0
ファイル: mert_unit_tests.py プロジェクト: glogou/tmp_testing
def unit_test_prime_product_count():

    # test 1, target number is 5
    # it will produce a sequence of factors: 1*2, 1*3, 1*5, 1 (in this order)
    begin_list = [1]
    factors_his = [0]* MAX_NUM_FACTORS
    target_num = 5
    primes = [2, 3, 5]
    factors_his, factors_his_cur_n_down = count_number_prime_product_recursive(begin_list, primes, target_num, factors_his)
    print target_num, factors_his, factors_his_cur_n_down

    all_1_factors_comm, all_2_factors_comm, all_3_factors_comm, all_4_factors_comm = get_select_factors(factors_his)
    # the following assertion is based on previous observations
    assert(all_1_factors_comm == 3)
    assert(all_2_factors_comm == 0)
    assert(all_3_factors_comm == 0)
    assert(all_4_factors_comm == 0)

    # test 2, target number is 6
    #  it will produce a sequence of  factors: 1*2*3, 1*2, 1*3, 1*5, 1 (in this order)
    begin_list = [1]
    factors_his = [0]* MAX_NUM_FACTORS
    target_num = 6
    primes = get_prime_list(target_num)
    factors_his, factors_his_cur_n_down = count_number_prime_product_recursive(begin_list, primes, target_num, factors_his)
    print target_num, factors_his, factors_his_cur_n_down

    all_1_factors_comm, all_2_factors_comm, all_3_factors_comm, all_4_factors_comm = get_select_factors(factors_his)
    # the following assertion is based on previous observations
    assert(all_1_factors_comm == 3)
    assert(all_2_factors_comm == 1)
    assert(all_3_factors_comm == 0)
    assert(all_4_factors_comm == 0)

    # test 3, it will produce a sequence of the follow factors: (in the order)
    #[1, 2, 3], [1, 2, 5], [1, 2, 7], [1, 2, 11], [1, 2, 13], [1, 2], [1, 3, 5], [1, 3, 7], [1, 3]
    # [1, 5], [1, 7], [1, 11], [1, 13], [1, 17], [1, 19], [1, 23]
    target_num = 28
    begin_list = [1]
    factors_his = [0]* MAX_NUM_FACTORS
    primes = get_prime_list(target_num)
    factors_his, factors_his_cur_n_down = count_number_prime_product_recursive(begin_list, primes, target_num, factors_his)
    print target_num, factors_his, factors_his_cur_n_down

    all_1_factors_comm, all_2_factors_comm, all_3_factors_comm, all_4_factors_comm = get_select_factors(factors_his)
    # the following assertion is based on previous observations
    assert(all_1_factors_comm == 9)
    assert(all_2_factors_comm == 7)
    assert(all_3_factors_comm == 0)
    assert(all_4_factors_comm == 0)

    # Test 4
    target_num = 70
    begin_list = [1]
    factors_his = [0]* MAX_NUM_FACTORS
    primes = get_prime_list(target_num)
    factors_his, factors_his_cur_n_down = count_number_prime_product_recursive(begin_list, primes, target_num, factors_his)
    print target_num, factors_his, factors_his_cur_n_down

    all_1_factors_comm, all_2_factors_comm, all_3_factors_comm, all_4_factors_comm = get_select_factors(factors_his)
    # the following assertion is not based on observation, we just run code once, and record number.
    # Those numbers are also produced by count_number_prime_product_with_4factors(...)
    # We believe those are correct, and use them for future. At least, if something are detected different in future,
    # we will can detect changes and try to find out why.
    assert(all_1_factors_comm == 19)
    assert(all_2_factors_comm == 20)
    assert(all_3_factors_comm == 4)
    assert(all_4_factors_comm == 0)