def main():
    global _array, _deleted

    _array = {}
    _deleted = set()

    user.init()

    # generate_pairs("input.txt", 100000)
    readData("input.txt")

    test_num = 10000
    error = 0

    for i in range(test_num):
        case = randint(0, 2)
        res = True
        if case == 0:
            res = delete()
        elif case == 1:
            res = checkFind()
        elif case == 2:
            res = checkFindDeleted()

        if not res:
            error += 1
Esempio n. 2
0
def main():
    global _book_catalog, _author_lst, _deleted

    _book_catalog = {}
    _author_lst = []
    _deleted = set()

    user.init()

    readData("data/library.txt")
    generate_invalid(500)

    test_num = 100000
    error = 0

    for i in range(test_num):
        case = randint(0, 4)
        res = True
        if case == 0:
            res = _delete()
        elif case == 1:
            res = checkFind()
        elif case == 2:
            res = checkFindDeleted()
        elif case == 3:
            res = checkFindAuthor()
        elif case == 4:
            res = restoreDeleted()

        if not res:
            print((case, i))
            error += 1
Esempio n. 3
0
def readGraph(input_file):
    global edges_dict, way, dist, start, end
    with open(input_file) as in_file:
        vertices, edges = map(int, in_file.readline().split())
        start, end = map(int, in_file.readline().split())
        user.init(vertices, edges)
        for e in range(edges):
            frm, to, weight = map(int, in_file.readline().split())
            edges_dict[(frm, to)] = weight
            user.addEdge(frm, to, weight)

        way = in_file.readline().rstrip()
        try:
            way = list(map(int, way.split()))
        except ValueError:
            way = WAY_NOT_EXIST

        dist = in_file.readline().rstrip()
        try:
            dist = int(dist)
        except ValueError:
            dist = INF
Esempio n. 4
0
def main():
    global _book_catalog, _author_lst, _deleted

    _book_catalog = {}
    _author_lst = []
    _deleted = set()

    user.init()

    readData("data/library.txt")
    generate_invalid(500)

    test_num = 100000
    error = 0

    step_show = test_num / 100
    j = 0
    print("[", end="")

    for i in range(test_num):
        case = randint(0, 4)
        res = True
        if case == 0:
            res = _delete()
        elif case == 1:
            res = checkFind()
        elif case == 2:
            res = checkFindDeleted()
        elif case == 3:
            res = checkFindAuthor()
        elif case == 4:
            res = restoreDeleted()

        error += 0 if res else 1

        j += 1
        if j > step_show:
            j = 0
            print(".", end="")
Esempio n. 5
0
def main():
    global _array, _deleted

    _array = {}
    _deleted = set()

    user.init()

    # generate_pairs("input.txt", 100000)
    readData("input.txt")

    test_num = 10000
    error = 0

    step_show = test_num / 100
    j = 0
    print("[", end="")

    for i in range(test_num):
        case = randint(0, 3)
        res = True
        if case == 0:
            res = delete()
        elif case == 1:
            res = checkFind()
        elif case == 2:
            res = checkFindDeleted()
        elif case <= 3:
            res = checkRestoreDeleted()

        error += 0 if res else 1

        j += 1
        if j > step_show:
            j = 0
            print(".", end="")
Esempio n. 6
0
import user, ATM
user.init(
    "d:/#full_stack/fullstack_python/Python/08ATM&SHOPING/shoping_user.json")


def join():
    return user.join({'shoping_bus': [], 'atm_card': 0})


def login(func):
    def _login(*info):
        ret = user.login()
        if ret == False:
            if input('is join a new user? y/n') in ['y', 'Y']:
                if join() == True:
                    _login(*info)
                return False
            else:
                _login(*info)
        func(*info)
        return True

    return _login


@login
def logout():
    return user.logout()


@login
Esempio n. 7
0
def main(input_file):
    _lst = []
    error = 0
    test_num = 0

    user.init()
    _cur = -1

    with open(input_file) as f_in:
        for line in f_in:
            pair = line.strip().split()

            if len(pair) != 1 and len(pair) != 2:
                continue

            key = pair[0]
            item = 0
            if len(pair) == 2:
                item = int(pair[1])

            if key == "empty":
                test_num += 1
                out_empty = user.empty()
                lst_empty = len(_lst) == 0
                if out_empty != lst_empty:
                    error += 1

            elif key == "set_first":
                if len(_lst) == 0:
                    continue

                _cur = 0
                user.set_first()

            elif key == "set_last":
                if len(_lst) == 0:
                    continue

                _cur = len(_lst) - 1
                user.set_last()

            elif key == "next":
                test_num += 1

                if len(_lst) == 0:
                    try:
                        user.next()
                    except StopIteration:
                        pass
                    else:
                        error += 1
                    continue

                if _cur == len(_lst) - 1:
                    try:
                        user.next()
                        error += 1
                    except StopIteration:
                        pass
                    continue

                _cur += 1
                try:
                    user.next()
                except StopIteration:
                    error += 1

            elif key == "prev":
                test_num += 1

                if len(_lst) == 0:
                    try:
                        user.prev()
                    except StopIteration:
                        pass
                    else:
                        error += 1
                    continue

                if _cur == 0:
                    try:
                        user.prev()
                        error += 1
                    except StopIteration:
                        pass
                    continue

                _cur -= 1
                try:
                    user.prev()
                except StopIteration:
                    error += 1

            elif key == "current":
                if len(_lst) == 0:
                    continue

                test_num += 1
                out_current = user.current()
                lst_current = _lst[_cur]
                if out_current != lst_current:
                    error += 1

            elif key == "insert_after":
                _lst.insert(_cur + 1, item)
                user.insert_after(item)
                if len(_lst) == 1:
                    _cur = 0

            elif key == "insert_before":
                _lst.insert(_cur, item)
                user.insert_before(item)
                if len(_lst) == 1:
                    _cur = 0
                else:
                    _cur += 1

            elif key == "delete":
                if len(_lst) == 0:
                    continue

                user.delete()
                _lst.pop(_cur)
                if _cur == len(_lst):
                    _cur = len(_lst) - 1

            elif key == "len":
                test_num += 1
                out_len = user.len()
                lst_len = len(_lst)
                if out_len != lst_len:
                    error += 1

            elif key == "damp":
                test_num += 1
                out = user.damp()
                if len(_lst) != len(out):
                    error += 1
                else:
                    for i in range(len(_lst)):
                        if _lst[i] != out[i]:
                            error += 1
                            break

            elif key == "swap_prev":
                if len(_lst) == 0 or _cur == 0:
                    continue

                _lst[_cur - 1], _lst[_cur] = _lst[_cur], _lst[_cur - 1]
                _cur -= 1
                user.swap_prev()

            elif key == "swap_next":
                if len(_lst) == 0 or _cur == len(_lst) - 1:
                    continue

                _lst[_cur], _lst[_cur + 1] = _lst[_cur + 1], _lst[_cur]
                _cur += 1
                user.swap_next()

        score = 100 * (test_num - error) / test_num
        return score if score > 35 else 0
Esempio n. 8
0
def main(input_file):
    _lst = []
    error = 0
    test_num = 0

    user.init()
    _cur = -1

    with open(input_file) as f_in:
        for line in f_in:
            pair = line.strip().split()

            if len(pair) != 1 and len(pair) != 2:
                continue

            key = pair[0]
            item = 0
            if len(pair) == 2:
                item = int(pair[1])

            if key == "empty":
                test_num += 1
                out_empty = user.empty()
                lst_empty = len(_lst) == 0
                if out_empty != lst_empty:
                    error += 1

            elif key == "reset":
                if len(_lst) == 0:
                    continue

                _cur = 0
                user.reset()

            elif key == "next":
                test_num += 1

                if len(_lst) == 0:
                    try:
                        user.next()
                    except StopIteration:
                        pass
                    else:
                        error += 1
                    continue

                if _cur == len(_lst) - 1:
                    try:
                        user.next()
                        error += 1
                    except StopIteration:
                        pass
                    continue

                _cur += 1
                try:
                    user.next()
                except StopIteration:
                    error += 1

            elif key == "current":
                if len(_lst) == 0:
                    continue

                test_num += 1
                out_current = user.current()
                lst_current = _lst[_cur]
                if out_current != lst_current:
                    error += 1

            elif key == "insert_after":
                _lst.insert(_cur + 1, item)
                user.insert_after(item)
                if len(_lst) == 1:
                    _cur = 0

        score = 100 * (test_num - error) / test_num

        return score if score > 35 else 0