def run():
    arr = [4,5,6,7,8,1,2,3,4,5,]

    N = input('How many test cases? : ')
    n = input('Average count of integers per test case? : ')
    s = input('Average integer value? : ')
    try:
        N = int(N)
        n = int(n)
        s = int(s)
    except:
        print("One of the values you entered could not be parsed into an integer.")
        print("Exiting")
        return
        

    print("Generating "+str(N)+" arrays of average length "+str(n),end='')
    for i in range(N):
        print(" test case "+str(i)+": Efficient: ",end='')
        count = random.randint(int(n/10),n*2)
        arr = []
        for j in range(count+2): # add 2 for minimum array size of 2
            num = random.randint(int(s/10),s*2) 
            arr.append(num)
        result_efficient = max_pairwise_product.max_pairwise_product(arr)
        result_naive = max_pairwise_product.max_pairwise_product_naive(arr)
        print(str(result_efficient),end='')
        print(", Naive:"+str(result_naive),end='')
        result = "FAIL"
        if result_efficient == result_naive:
            result = "PASS" 
        print(", RESULT? : "+result)
        if result == "FAIL": 
            print("exiting ..")
            return;
 def testing_all_cases(self):
     numlist = []
     length = randint(2, 11)
     for n in range(0, length):
         numlist.append(randint(1, 100))
     print(length, numlist)
     solution1 = pairwise_max_product(length, numlist)
     solution2 = max_pairwise_product(length, numlist)
     print(f'solution1 = {solution1}')
     print(f'solution2 = {solution2}')
     #for digit in numlist:
     #self.assertEqual(pairwise_max_product(length,numlist), max_pairwise_product(length,numlist))
     self.assertEqual(solution1, solution2)
Esempio n. 3
0
def Stress_Test(N, M):
    while True:
        n = random.randint(2, N)
        A = list(range(n))
        for i in A:
            A[i] = random.randint(0, M)
        print(A)

        naive_result = max_pairwise_product.max_pairwise_product(A)
        fast_result = max_pairwise_product_fast.max_pairwise_product_fast(A)

        if naive_result == fast_result:
            print("OK!")
        else:
            print("Wrong Answer!", naive_result, fast_result)
            return
Esempio n. 4
0
def test_max(cnt, n, m):

    for c in range(cnt):
        print('Run #: {}'.format(c))

        arr_len = random.randint(2, n)
        arr = []
        for i in range(arr_len):
            arr.append(random.randint(0, m))

        res_naive = fn.max_pairwise_product(arr)
        res_fast = fn.max_pairwise_product_fast(arr)

        if res_naive != res_fast:
            print('ERROR: naive: {} - fast: {} - diff: {}'.format(
                res_naive, res_fast, res_naive - res_fast))
        else:
            print('OK')
Esempio n. 5
0
def stress_test(array_len, max_num):
    nums = []
    for num in range(random.randint(1, array_len)):
        num = random.randint(0, max_num)
        nums.append(num)

    naive_result = max_pairwise_product(nums)
    fast_result = get_max_pairwaise_fast(nums)

    while True:
        if naive_result != fast_result:
            print('\n---- PROBLEM ------\n')
            print('Array length: ', array_len)
            print('Numbers: ', nums)
            print('Naive Solution: ', naive_result)
            print('Fast Solution: ', fast_result)
            print('\n---- ------- ------\n')
            break
        else:
            print('--- OK ---')
Esempio n. 6
0
def stress_test(N, M):

    while True:
        n = random.randint(2, N)
        print(n)

        rand_list = random.sample(range(M), n)
        #rand_list_chr = [x for x in rand_list]
        #print(rand_list)
        #print(rand_list_chr)
        #print(' '.join(rand_list_chr)+'\n')
        input_numbers = rand_list

        res1 = max_pairwise_product.max_pairwise_product(input_numbers)
        print(res1)
        res2 = max_pairwise_product_fast.max_pairwise_product(input_numbers)
        print(res2)

        if (res1 != res2):
            print('Wrong answer: {} {}'.format(res1, res2))
            break
        else:
            print('OK')
 def test_random_inputs(self):
     self.assertEqual(max_pairwise_product(self.callable_arr),
                      self.expected)
Esempio n. 8
0
 def testMaxPairwiseProductRepeatedElements(self):
     num = 5
     numbers_list = [10, 10, 20, 40, 60]
     product1 = max_pairwise_product(numbers_list)
     product2 = max_pairwise_product_fast(numbers_list)
     self.assertEquals(product1, product2)