from random import sample, randint
import pytest

from ads.exercises.tree import *
from ads.utils import gen_bst, load_json_data
#==============================================================================
DATA = load_json_data("tree")
#==============================================================================


@pytest.mark.parametrize("L, expected", DATA["height_bt"])
def test_height_bt(L, expected):
    bst = gen_bst(L)
    assert height_bt_v1(bst._root) == expected
    assert height_bt_v2(bst._root) == expected + 1


@pytest.mark.parametrize("L, expected", DATA["width_bt"])
def test_width_bt(L, expected):
    bst = gen_bst(L)
    assert width_bt(bst._root) == expected


@pytest.mark.parametrize("L, expected", DATA["count_leaves"])
def test_count_leaves(L, expected):
    bst = gen_bst(L, type=AVL)
    assert count_leaves(bst._root) == expected


# def test_tree():
#     A = []
import pytest

from ads.utils import load_json_data
from ads.exercises.mathematical import *

DATA = load_json_data("mathematical")


@pytest.mark.parametrize("k, expected", DATA["integer_square_root"])
def test_squre_root(k, expected):
    assert integer_square_root(k) == expected
import pytest

from ads.exercises.recursion import *
from ads.utils import load_json_data
# from ece.recursion.all_recursion import n_choose_k

DATA = load_json_data('recursion')

############################  Permutation Testing  ###########################


@pytest.mark.parametrize('permutable, expected', DATA["permute_str_v1"])
def test_permute_str_v1(permutable, expected):
    assert permute_str_v1(permutable) == expected


@pytest.mark.parametrize('permutable, expected', DATA["permute_str_v2"])
def test_permute_str_v2(permutable, expected):
    assert permute_str_v2(permutable) == expected


@pytest.mark.parametrize('permutable, expected', DATA["permute_str_v3"])
def test_permute_str_v3(permutable, expected):
    assert permute_str_v3(permutable) == expected


@pytest.mark.parametrize('permutable, expected', DATA["permute_list_v1"])
def test_permute_list_v1(permutable, expected):
    assert permute_list_v1(permutable) == expected

Beispiel #4
0
from random import *
import unittest
import pytest

from ads.exercises.searching.searching import *
from ads.exercises.searching import *
from ads.utils import load_json_data, yellow

DATA = load_json_data('searching')


@pytest.mark.parametrize("L, k, expected", DATA["search_first_of_k"])
def test_search_first_of_k(L, k, expected):
    assert search_first_of_k(L, k) == expected


@pytest.mark.parametrize("L, expected", DATA["magic_index"])
def test_magic_index(L, expected):
    assert magic_index(L) == expected


@pytest.mark.parametrize("L, expected", DATA["magic_index_v2"])
def test_magic_index_v2(L, expected):
    assert magic_index_v2(L) == expected


@pytest.mark.parametrize("L, expected", DATA["search_smallest"])
def test_search_first_of_k(L, expected):
    assert search_smallest(L) == expected

Beispiel #5
0
import pytest

from ads.utils import load_json_data
from ads.exercises.dynamic_programming import *

#==============================================================================
DATA = load_json_data('dynamic_programming')
#==============================================================================


# **************************** test_fib() ****************************** #
@pytest.mark.parametrize('n, expected', DATA["fib"])
def test_fib(n, expected):
    assert fib_rec(n) == expected
    assert fib_dp_tbl(n) == expected
    assert fib_dp_memo(n) == expected


# ********************** test_stairs_hop_ways() ************************ #
def test_stairs_hop_ways():
    for i in range(4, 50):
        tbl = stairs_hop_3ways_tbl(i)
        memo3 = stairs_hop_3ways_memo(i)
        memok = stairs_hop_kways_memo(i, 3)

        assert memo3 == memok == tbl

        # print(stairs_hop_3ways_tbl(i))
        # print(stairs_hop_kways_memo(i, 3))
        # print(stairs_hop_3ways_memo(i))