Example #1
0
def test_swap_invalid_j():
    swap_me = MyList("swap")
    swap_me.swap(1, 10)
    assert get_MyList(swap_me) == "swap"
Example #2
0
def test_pop_back_empty():
    test_popb = MyList()
    test_popb.pop_back()
    assert get_MyList(test_popb) == ""
Example #3
0
# Test MyList:

from MyList import MyList

mylist = MyList(['a', 'b', 'c'])
mylist.append('y')
mylist.prepend('z')
print(mylist)
Example #4
0
def test_push_back_empty():
    test_pb = MyList()
    for ch in "abc":
        test_pb.push_back(ch)
    assert get_MyList(test_pb) == "abc"
Example #5
0
def test_default_constructor():
    def_constructor = get_MyList(MyList())
    assert len(def_constructor) == 0
Example #6
0
def test_string_constructor():
    str_constructor = MyList("Iamastring")
    assert get_MyList(str_constructor) == "Iamastring"
Example #7
0
def test_push_front_empty():
    test_pf = MyList()
    for ch in "olleh":
        test_pf.push_front(ch)
    assert get_MyList(test_pf) == "hello"
Example #8
0
def test_reverse_empty():
    test_rev = MyList()
    test_rev.reverse()
    assert get_MyList(test_rev) == ""
Example #9
0
def test_size():
    test_list = get_MyList(MyList("abcdefghij"))
    assert len(test_list) == 10
Example #10
0
def test_copy_constructor_len():
    copy_from = MyList("original")
    copy_to = get_MyList(MyList(copy_from))
    copy_from = get_MyList(copy_from)
    assert len(copy_from) == 8 and len(copy_to) == 8
Example #11
0
def test_reverse_nonempty():
    test_rev = MyList("reverse")
    test_rev.reverse()
    assert get_MyList(test_rev) == "esrever"
Example #12
0
def test_insert_at_pos_valid():
    my_list = MyList("testing")
    my_list.insert_at_pos(2, 'a')
    assert get_MyList(my_list) == "teasting"
Example #13
0
def test_swap_on_empty():
    empty = MyList()
    empty.swap(1, 2)
    assert get_MyList(empty) == ""
Example #14
0
def test_swap_both_invalid():
    swap_me = MyList("swap")
    swap_me.swap(-1, 200)
    assert get_MyList(swap_me) == "swap"
Example #15
0
def test_addition_operator_a_nonempty_b_empty():
    test_str = MyList("123")
    test_str2 = MyList()
    test_str3 = test_str + test_str2
    assert get_MyList(test_str3) == "123"
Example #16
0
def test_find_invalid_char():
    test_string = MyList("teststring")
    assert test_string.find_MyList("z") == -1
Example #17
0
def test_print(capfd):
    test_output = MyList("testoutput")
    test_output.print_list()
    out, err = capfd.readouterr()
    only_chars = "".join(re.findall('([a-z])', out))
    assert only_chars == "testoutput"
Example #18
0
def test_find_valid_MyList():
    test_string = MyList("teststring")
    assert test_string.find_MyList(MyList("rin")) == 6
Example #19
0
def test_push_front_nonempty():
    test_pf = MyList("world")
    for ch in "olleh":
        test_pf.push_front(ch)
    assert get_MyList(test_pf) == "helloworld"
Example #20
0
def test_find_invalid_MyList():
    test_string = MyList("teststring")
    assert test_string.find_MyList(MyList("zoo")) == -1
Example #21
0
def test_push_back_nonempty():
    test_pb = MyList("hello")
    for ch in "world":
        test_pb.push_back(ch)
    assert get_MyList(test_pb) == "helloworld"
Example #22
0
def test_find_empty_list_MyList():
    test_string = MyList()
    assert test_string.find_MyList(MyList("test")) == -1
Example #23
0
def test_pop_front_empty():
    test_popf = MyList()
    test_popf.pop_front()
    assert get_MyList(test_popf) == ""
Example #24
0
def test_equals_operator_nonempty():
    test_string = MyList("test")
    test_string.reassign(MyList("newstring"))
    test_string = get_MyList(test_string)
    assert test_string == "newstring"
Example #25
0
def test_pop_front_nonempty():
    test_popf = MyList("popping")
    for _ in xrange(3):
        test_popf.pop_front()
    assert get_MyList(test_popf) == "ping"
Example #26
0
def test_equals_operator_nonempty_mem_check():
    test_string = MyList("test")
    test_str2 = MyList("newstring")
    test_string.reassign(test_str2)
    test_str2.pop_back()
    assert get_MyList(test_string) != get_MyList(test_str2)
Example #27
0
def test_pop_back_nonempty():
    test_popb = MyList("popping")
    for _ in xrange(4):
        test_popb.pop_back()
    assert get_MyList(test_popb) == "pop"
Example #28
0
def test_addition_operator_a_nonempty_b_nonempty():
    test_str = MyList("abc")
    test_str2 = MyList("def")
    test_str3 = test_str + test_str2
    assert get_MyList(test_str3) == "abcdef"
Example #29
0
    for val in tabRandom:  #serching
        for x in tabCopy:  #find values in the unsorted tabCopy
            if (val == x):
                break
    end = time.time()
    sB.append(end - start)

    start = time.time()
    for val in tabRandom:  #find values in the unsorted tabCopy by bisection search
        Bisection(val, tabCopy)
    end = time.time()
    sbB.append(end - start)

    ############################ 3 ################################################
    start = time.time()
    myList = MyList()  ###List creation
    for elem in tabRandom:
        myList.add(elem)
    end = time.time()
    cL.append(end - start)

    start = time.time()
    for elem in tabRandom:  ###Searching
        myList.has(
            elem)  #If it has an element myList.has(elem) will return True
    end = time.time()
    sL.append(end - start)

    ################################## 4 ##########################################
    start = time.time()
    tree = Tree()  #BTS creation
Example #30
0
def test_swap_invalid_i():
    swap_me = MyList("swap")
    swap_me.swap(8, 2)
    assert get_MyList(swap_me) == "swap"