Example #1
0
def test_sum_array():
    """
    test the correctness of sum_array
    """

    assert sum_array([1, 2, 3, 4]) == 10, 'incorrect'
    assert sum_array([1, -7, 3, 4]) == 1, 'incorrect'
Example #2
0
def test_functions():
    """
    make sure all functions work correctly
    """

    assert factorial(4) == 24, 'incorrect'
    assert fibonacci(8) == 21, 'incorrect'
    assert reverse(
        'A sentence that has to be reversed by the reverse function'
    ) == 'noitcnuf esrever eht yb desrever eb ot sah taht ecnetnes A', 'incorrect'
    assert sum_array([[5, 5], [20], [2, 1]]) == 33, 'incorrect'
    assert bubble_sort([59, 69, 3, 58, 494, 4, 13,
                        30]) == [59, 3, 58, 69, 4, 13, 30, 494], 'incorrect'

    #lists to test merge_sort function

    x = [34, 5, 2, 6]
    y = [12, 34, 54, 1]
    assert merge_sort(x + y) == [1, 2, 5, 6, 12, 34, 34, 54], 'incorrect'
    assert quick_sort([5, 6, 3, 7, 11, 44]) == [3, 5, 6, 7, 11,
                                                44], 'incorrect'
Example #3
0
from recursion import sum_array, factorial, reverse, fibonacci
from sorting import bubble_sort, merge_sort, quick_sort

print(sum_array([1, 2, 3]))
print(fibonacci(10))
print(factorial(5))
print(reverse("abcdef"))
print(bubble_sort([5, 4, 1, 2, 4, 9]))
print(merge_sort([1, 3, 2, 5, 4, 7, 6]))
print(quick_sort([3, 2, 4, 5, 7, 6]))
Example #4
0
 def test_sum_array_empty(self):
     self.assertEqual(recursion.sum_array([]), 0)
Example #5
0
 def test_sum_array(self):
     array = [1, 2, 3, 4, 5, 6]
     self.assertEqual(recursion.sum_array(array), 21)
Example #6
0
from recursion import sum_array, factorial, reverse, fibonacci
from sorting import bubble_sort, merge_sort, quick_sort

assert sum_array([1,2,3]) == 6
assert factorial(5) == 120
assert reverse('hello world') == 'dlrow olleh'
assert fibonacci(3) = 1
assert bubble_sort([1,3,5,2,4]) == [1, 2, 3, 4, 5]
assert merge_sort([3,0,6,33,9]) == [0, 3, 6, 9, 33]
assert quick_sort([3,1,7,54,2]) == [1, 2, 3, 7, 54]