def test_swap_invalid_j(): swap_me = MyList("swap") swap_me.swap(1, 10) assert get_MyList(swap_me) == "swap"
def test_pop_back_empty(): test_popb = MyList() test_popb.pop_back() assert get_MyList(test_popb) == ""
# Test MyList: from MyList import MyList mylist = MyList(['a', 'b', 'c']) mylist.append('y') mylist.prepend('z') print(mylist)
def test_push_back_empty(): test_pb = MyList() for ch in "abc": test_pb.push_back(ch) assert get_MyList(test_pb) == "abc"
def test_default_constructor(): def_constructor = get_MyList(MyList()) assert len(def_constructor) == 0
def test_string_constructor(): str_constructor = MyList("Iamastring") assert get_MyList(str_constructor) == "Iamastring"
def test_push_front_empty(): test_pf = MyList() for ch in "olleh": test_pf.push_front(ch) assert get_MyList(test_pf) == "hello"
def test_reverse_empty(): test_rev = MyList() test_rev.reverse() assert get_MyList(test_rev) == ""
def test_size(): test_list = get_MyList(MyList("abcdefghij")) assert len(test_list) == 10
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
def test_reverse_nonempty(): test_rev = MyList("reverse") test_rev.reverse() assert get_MyList(test_rev) == "esrever"
def test_insert_at_pos_valid(): my_list = MyList("testing") my_list.insert_at_pos(2, 'a') assert get_MyList(my_list) == "teasting"
def test_swap_on_empty(): empty = MyList() empty.swap(1, 2) assert get_MyList(empty) == ""
def test_swap_both_invalid(): swap_me = MyList("swap") swap_me.swap(-1, 200) assert get_MyList(swap_me) == "swap"
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"
def test_find_invalid_char(): test_string = MyList("teststring") assert test_string.find_MyList("z") == -1
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"
def test_find_valid_MyList(): test_string = MyList("teststring") assert test_string.find_MyList(MyList("rin")) == 6
def test_push_front_nonempty(): test_pf = MyList("world") for ch in "olleh": test_pf.push_front(ch) assert get_MyList(test_pf) == "helloworld"
def test_find_invalid_MyList(): test_string = MyList("teststring") assert test_string.find_MyList(MyList("zoo")) == -1
def test_push_back_nonempty(): test_pb = MyList("hello") for ch in "world": test_pb.push_back(ch) assert get_MyList(test_pb) == "helloworld"
def test_find_empty_list_MyList(): test_string = MyList() assert test_string.find_MyList(MyList("test")) == -1
def test_pop_front_empty(): test_popf = MyList() test_popf.pop_front() assert get_MyList(test_popf) == ""
def test_equals_operator_nonempty(): test_string = MyList("test") test_string.reassign(MyList("newstring")) test_string = get_MyList(test_string) assert test_string == "newstring"
def test_pop_front_nonempty(): test_popf = MyList("popping") for _ in xrange(3): test_popf.pop_front() assert get_MyList(test_popf) == "ping"
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)
def test_pop_back_nonempty(): test_popb = MyList("popping") for _ in xrange(4): test_popb.pop_back() assert get_MyList(test_popb) == "pop"
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"
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
def test_swap_invalid_i(): swap_me = MyList("swap") swap_me.swap(8, 2) assert get_MyList(swap_me) == "swap"