def test_grayorder(): grey_code = generate_grey_code(3, 0, 2) is_different = False for i in range(0, len(grey_code) - 1): if not grayorder(grey_code[i], grey_code[i + 1]): is_different = True return is_different
def test_rank_sort(): num_fields = 3 # GENERATE GREY CODE AND SHUFFLE grey_code = generate_grey_code(fields=num_fields, start=0, end=2) randomized_grey_code = grey_code.copy() random.shuffle(randomized_grey_code) ranked, iterations = rank_sort(randomized_grey_code, 3) is_different = False for grey, sorted in zip(grey_code, ranked): if grey[-1] != sorted[-1]: is_different = True print("{} {} -> {}".format(grey, sorted[:-1], sorted[-1])) return is_different
def test_gray_rank(): num_fields = 3 # GENERATE GREY CODE AND SHUFFLE grey_code = generate_grey_code(fields=num_fields, start=0, end=3) is_different = False for i in range(0, len(grey_code)): rank = gray_rank(grey_code[i], 4) if rank == i: is_match = True else: is_match = False is_different = True # DEBUG ONLY #print("{} -> {} | {}".format(grey_code[i], rank, is_match)) return is_different
def test_radix_sort(): num_fields = 3 # GENERATE GREY CODE AND SHUFFLE grey_code = generate_grey_code(fields=num_fields, start=0, end=3) randomized_grey_code = grey_code.copy() random.shuffle(randomized_grey_code) # SORT sorted_grey, iterations = radix_sort(randomized_grey_code) is_different = False for grey, sorted in zip(grey_code, sorted_grey): if grey != sorted: is_different == True # FOR DEBUGGING #print("{} | {} | {}".format(grey, sorted, grey == sorted)) return is_different
def test_gray_order_sort(): num_fields = 3 # GENERATE GREY CODE AND SHUFFLE grey_code = generate_grey_code(fields=num_fields, start=0, end=3) randomized_grey_code = grey_code.copy() random.shuffle(randomized_grey_code) qs = QuickSort() sorted = qs.quick_sort(randomized_grey_code, 0, len(randomized_grey_code) - 1, grayorder) is_different = False for grey, sort in zip(grey_code, sorted): if grey == sort: is_same = True else: is_different = True is_same = False print("{} | {} | {}".format(grey, sort, is_same)) return is_different