示例#1
0
def test_addition_operator_mem_check():
    test_str = MyList("abc")
    test_str2 = MyList("def")
    test_str3 = test_str + test_str2
    test_str2.pop_back()

    assert get_MyList(test_str3) == "abcdef"
def test_copy_constructor_diff():
    copy_from = MyList("original")
    copy_to = MyList(copy_from)
    copy_to.push_front('a')
    copy_to = get_MyList(copy_to)
    copy_from = get_MyList(copy_from)
    assert len(copy_from) == 8 and len(copy_to) == 9
def test_addition_operator_mem_check():
    test_str  = MyList("abc")
    test_str2 = MyList("def")
    test_str3 = test_str + test_str2
    test_str2.pop_back()

    assert get_MyList(test_str3) == "abcdef"
示例#4
0
def test_copy_constructor_diff():
    copy_from = MyList("original")
    copy_to = MyList(copy_from)
    copy_to.push_front('a')
    copy_to = get_MyList(copy_to)
    copy_from = get_MyList(copy_from)
    assert len(copy_from) == 8 and len(copy_to) == 9
示例#5
0
def intersect(operands):
    first = lookup(operands[0])
    second = lookup(operands[1])

    result = []
    if len(first) == 0 or len(second) == 0:
        return MyList([])
    else:
        carry_on = True
    while carry_on:
        a = first.current_val()
        b = second.current_val()

        if a == b:
            result.append(a)
            carry_on &= first.next()
            carry_on &= second.next()
        elif a < b:
            if first.has_skip() and first.skip_val() <= b:
                first.skip()
            else:
                carry_on &= first.next()
        else:
            if second.has_skip() and second.skip_val() <= a:
                second.skip()
            else:
                carry_on &= second.next()
    del first
    del second
    return MyList(result)
示例#6
0
 def __init__(self, *args, **kwargs):
     """
     Initialize a new FileList instance.
     """
     MyList.__init__(self, *args, **kwargs)
     listmix.ListRowHighlighter.__init__(self, color="#EDF2FE")
     listmix.ListCtrlAutoWidthMixin.__init__(self)
     self.InitUI()
def test_sum_num():
    listA = MyList()
    assert (listA.sum_numbers() == 0)
    listA.sum_numbers(1)
    assert (listA.sum_numbers() == 1)
    listA.sum_numbers(5)
    assert (listA.sum_numbers() == 6)
def test_minmax():
    listC = MyList()
    assert (listC.findextremes() == 0)
    listC.findextremes(3)
    assert (listC.findextremes() == [0, 3])
    listC.findextremes(-1)
    assert (listC.findextremes() == [-1, 3])
示例#9
0
def lookup(word):
    if type(word) is str:
        if config.ELIMINATE_STOP_WORDS and is_stopword(word):
            return MyList(master_postings)
        elif config.ELIMINATE_NUMBERS and is_number(word):
            return MyList(master_postings)
        if word in dictionary:
            postings_file.seek(dictionary[word]['start'])
            raw = postings_file.read(dictionary[word]['size'])
            return MyList(pickle.loads(raw))
        else:
            return MyList([])
    else:
        return word
示例#10
0
def union(operands):
    first = lookup(operands[0]).to_list()
    second = lookup(operands[1]).to_list()

    i = j = 0
    result = []

    while i < len(first) and j < len(second):
        if first[i] == second[j]:
            result.append(first[i])
            i += 1
            j += 1
        elif first[i] < second[j]:
            result.append(first[i])
            i += 1
        else:
            result.append(second[j])
            j += 1

    # add remaining, one of the following is actually empty
    result.extend(first[i:])
    result.extend(second[j:])
    del first
    del second
    return MyList(result)
def test_maxdiff():
    listB = MyList()
    assert (listB.MaxDiff() == 0)
    listB.MaxDiff(5)
    assert (listB.MaxDiff() == 5)
    listB.MaxDiff(8)
    assert (listB.MaxDiff() == 5)
示例#12
0
def test_size():
    test_list = get_MyList(MyList("abcdefghij"))
    assert len(test_list) == 10
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_invalid_MyList():
    test_string = MyList("teststring")
    assert test_string.find_MyList(MyList("zoo")) == -1
def test_equals_operator_nonempty():
    test_string = MyList("test")
    test_string.reassign(MyList("newstring"))
    test_string = get_MyList(test_string)
    assert test_string == "newstring"
示例#16
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"
def test_find_invalid_char():
    test_string = MyList("teststring")
    assert test_string.find_MyList("z") == -1
示例#18
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"
def test_pop_front_nonempty():
    test_popf = MyList("popping")
    for _ in xrange(3):
        test_popf.pop_front()
    assert get_MyList(test_popf) == "ping"
示例#20
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"
示例#21
0
def test_push_front_empty():
    test_pf = MyList()
    for ch in "olleh":
        test_pf.push_front(ch)
    assert get_MyList(test_pf) == "hello"
示例#22
0
def test_string_constructor():
    str_constructor = MyList("Iamastring")
    assert get_MyList(str_constructor) == "Iamastring"
示例#23
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"
示例#24
0
def test_find_valid_MyList():
    test_string = MyList("teststring")
    assert test_string.find_MyList(MyList("rin")) == 6
def test_push_front_empty():
    test_pf = MyList()
    for ch in "olleh":
        test_pf.push_front(ch)
    assert get_MyList(test_pf) == "hello"
示例#26
0
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_push_back_empty():
    test_pb = MyList()
    for ch in "abc":
        test_pb.push_back(ch)
    assert get_MyList(test_pb) == "abc"
示例#28
0
def test_pop_front_empty():
    test_popf = MyList()
    test_popf.pop_front()
    assert get_MyList(test_popf) == ""
def test_pop_back_nonempty():
    test_popb = MyList("popping")
    for _ in xrange(4):
        test_popb.pop_back()
    assert get_MyList(test_popb) == "pop"
示例#30
0
def test_default_constructor():
    def_constructor = get_MyList(MyList())
    assert len(def_constructor) == 0
def test_reverse_empty():
    test_rev = MyList()
    test_rev.reverse()
    assert get_MyList(test_rev) == ""
示例#32
0
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_find_valid_MyList():
    test_string = MyList("teststring")
    assert test_string.find_MyList(MyList("rin")) == 6
示例#34
0
def test_pop_back_empty():
    test_popb = MyList()
    test_popb.pop_back()
    assert get_MyList(test_popb) == ""
def test_find_empty_list_MyList():
    test_string = MyList()
    assert test_string.find_MyList(MyList("test")) == -1
示例#36
0
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_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)
示例#38
0
# Test MyList:

from MyList import MyList

mylist = MyList(['a', 'b', 'c'])
mylist.append('y')
mylist.prepend('z')
print(mylist)
示例#39
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)
def test_swap_invalid_j():
    swap_me = MyList("swap")
    swap_me.swap(1,10)
    assert get_MyList(swap_me) == "swap"
def test_push_front_nonempty():
    test_pf = MyList("world")
    for ch in "olleh":
        test_pf.push_front(ch)
    assert get_MyList(test_pf) == "helloworld"
示例#42
0
def test_find_invalid_char():
    test_string = MyList("teststring")
    assert test_string.find_MyList("z") == -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_swap_invalid_i():
    swap_me = MyList("swap")
    swap_me.swap(8,2)
    assert get_MyList(swap_me) == "swap"
def test_pop_front_empty():
    test_popf = MyList()
    test_popf.pop_front()
    assert get_MyList(test_popf) == ""
示例#46
0
def test_find_invalid_MyList():
    test_string = MyList("teststring")
    assert test_string.find_MyList(MyList("zoo")) == -1
def test_pop_back_empty():
    test_popb = MyList()
    test_popb.pop_back()
    assert get_MyList(test_popb) == ""
示例#48
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"
def test_swap_both_valid():
    swap_me = MyList("swap")
    swap_me.swap(1,2)
    assert get_MyList(swap_me) == "sawp"
示例#50
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"
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_reverse_nonempty():
    test_rev = MyList("reverse")
    test_rev.reverse()
    assert get_MyList(test_rev) == "esrever"
def test_swap_both_invalid():
    swap_me = MyList("swap")
    swap_me.swap(-1,200)
    assert get_MyList(swap_me) == "swap"
示例#54
0
def test_find_empty_list_MyList():
    test_string = MyList()
    assert test_string.find_MyList(MyList("test")) == -1
示例#55
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
def test_swap_on_empty():
    empty = MyList()
    empty.swap(1, 2)
    assert get_MyList(empty) == ""