コード例 #1
0
def StartAlgorithm():
    global data
    speed = int(speedScale.get())
    if speed == 2:
        speed = 1.5
    elif speed == 3:
        speed = 0.1
    elif speed == 4:
        speed = 0.05
    elif speed == 5:
        speed = 0.01
    elif speed == 6:
        speed = 0.005
    elif speed == 7:
        speed = 0.001

    search = int(searchEntry.get())
    if selected_algo.get() == "Bubble Sort":
        bubble_sort(data, drawData, speed)
    elif selected_algo.get() == "Selection Sort":
        selection_sort(data, drawData, speed)
    elif selected_algo.get() == "Insertion Sort":
        insertion_sort(data, drawData, speed)
    elif selected_algo.get() == "Merge Sort":
        merge_sort(data, 0, len(data) - 1, drawData, speed)
        drawData(data, ['light green' for x in range(len(data))])
        time.sleep(speed)
    elif selected_algo.get() == "Quick Sort":
        quick_sort(data, drawData, speed)
    elif algMenu.get() == 'Linear Search':
        linear_search(data, search, drawData, speedScale.get())
    elif algMenu.get() == 'Binary Search':
        merge_sort(data, 0, len(data) - 1, drawData, speed)
        drawData(data, ['red' for x in range(len(data))])
        binary_search(data, search, drawData, speedScale.get())
コード例 #2
0
ファイル: binary_test.py プロジェクト: mingyun/Coder-s-code
def test_duplicate():
    assert binary_search(4, VALUES) == 2
コード例 #3
0
ファイル: binary_test.py プロジェクト: mingyun/Coder-s-code
def test_first():
    assert binary_search(1, VALUES) == 0
コード例 #4
0
ファイル: binary_test.py プロジェクト: mingyun/Coder-s-code
def test_missing_start():
    assert binary_search(-3, VALUES) == -1
コード例 #5
0
ファイル: binary_test.py プロジェクト: mingyun/Coder-s-code
def test_last():
    assert binary_search(10, VALUES) == 7
コード例 #6
0
ファイル: binary_test.py プロジェクト: mingyun/Coder-s-code
def test_middle():
    assert binary_search(5, VALUES) == 4
コード例 #7
0
 def test_binarySearch_2(self):
     self.assertEqual(binary_search([5, 6, 7, 8, 9], 9), 4)
コード例 #8
0
 def test_binarySearch_1(self):
     self.assertEqual(binary_search([1, 2, 3, 4, 5], 1), 0)
コード例 #9
0
 def test_binarySearch_4(self):
     self.assertEqual(binary_search([1, 2, 3, 4, 5], 6), -1)
コード例 #10
0
# print opening
space(3)
border('D')
print("Target:", target)
print("Input Size:", MAX)

# LINEAR SEARCH TEST
start = time.time()
res = linear_search(test, target)
end = time.time()
border('S')
space(1)
print("Linear Search Timer: ", end - start, "s", sep='')
print("Index Returned: ", res, sep='')
space(1)
border('M')

# BINARY SEARCH TEST
start = time.time()
res = binary_search(test, target)
end = time.time()
border('M')
space(1)
print("Binary Search Timer: ", end - start, "s", sep='')
print("Index Returned: ", res, sep='')
space(1)

# print closing
border('D')
space(3)
コード例 #11
0
def test_for_array_with_equal_elements():
    arr = [1, 2, 3, 4, 5, 5, 6, 7, 8]
    x = 5
    user_output = binarySearch.binary_search(arr, x)
    assert user_output == 4, "test Passed"
コード例 #12
0
def test_for_odd_length_array_with_last_element():
    arr = [1, 2, 3, 4, 5, 6, 7, 10, 12, 15, 17, 18, 20]
    x = 20
    user_output = binarySearch.binary_search(arr, x)
    assert user_output == 12, "test Passed"
コード例 #13
0
def test_for_odd_length_array_with_element_in_middle():
    arr = [1, 2, 3, 4, 5, 6, 7]
    x = 3
    user_output = binarySearch.binary_search(arr, x)
    assert user_output == 2, "test Passed"
コード例 #14
0
def test_for_even_length_array_with_element_in_first_half():
    arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
    x = 1
    user_output = binarySearch.binary_search(arr, x)
    assert user_output == 0, "test Passed"
コード例 #15
0
def test_for_valid_input():
    arr = ['a', 'b', 'c', 'd', 'e']
    x = "e"
    user_output = binarySearch.binary_search(arr, x)
    assert user_output == 4, "test Passed"
コード例 #16
0
from selectionSort import selection_sort
from insertionSort import insertion_sort
from bubbleSort import bubble_sort
from binarySearch import binary_search
import random

random_array = [random.randint(1, 100) for _ in range(100)]

print("Selection sort time:")
selection_sort(random_array)

print(binary_search(random_array, 76))

print("Insertion sort time:")
insertion_sort(random_array)

print("Bubble sort time:")
bubble_sort(random_array)