Ejemplo n.º 1
0
    def test_overflow(self):
        q = FixedQueue(0)
        with self.assertRaises(Exception):
            q.enqueue(0)

        q = FixedQueue(1)
        q.enqueue(0)
        with self.assertRaises(Exception):
            q.enqueue(0)
Ejemplo n.º 2
0
 def test_underflow(self):
     q = FixedQueue(10)
     with self.assertRaises(Exception):
         q.dequeue()
     
     q.enqueue(0)
     q.dequeue()
     with self.assertRaises(Exception):
         q.dequeue()
Ejemplo n.º 3
0
 def test_enqueue_dequeue(self):
     q = FixedQueue(6)
     q.enqueue(4)
     q.enqueue(1)
     q.enqueue(3)
     self.assertEqual(q.dequeue(), 4)
     
     q.enqueue(8)
     self.assertEqual(q.dequeue(), 1)
     self.assertEqual(q._xs, [4, 1, 3, 8, None, None])
Ejemplo n.º 4
0
def test_enqueue():

    q = FixedQueue(3)

    q.enqueue(1)
    q.enqueue(2)
    q.enqueue(3)

    assert (len(q) == 3)

    with pytest.raises(Exception):
        q.enqueue(4)
Ejemplo n.º 5
0
from enum import Enum
from fixed_queue import FixedQueue

Menu = Enum('Menu', ['인큐', '디큐', '피크', '검색', '덤프', '종료'])


def select_menu() -> Menu:
    s = [f'({m.value}){m.name}' for m in Menu]
    while True:
        print(*s, sep='  ', end='')
        n = int(input(': '))
        if 1 <= n <= len(Menu):
            return Menu(n)


q = FixedQueue(64)

while True:
    print(f'현재 데이터 개수: {len(q)} / {q.capacity}')
    menu = select_menu()

    if menu == Menu.인큐:
        x = int(input('인큐할 데이터를 입력하세요.:'))
        try:
            q.enqueue(x)
        except FixedQueue.Full:
            print('큐가 가득 찼습니다')

    elif menu == Menu.디큐:
        try:
            x = q.dequeue()
Ejemplo n.º 6
0
from fixed_queue import FixedQueue

Menu = Enum('Menu', ['인큐', '디큐', '피크', '검색', '덤프', '종료'])


def select_menu() -> Menu:
    """메뉴 선택"""
    s = [f'({m.value}){m.name}' for m in Menu]
    while True:
        print(*s, sep='   ', end='')
        n = int(input(': '))
        if 1 <= n <= len(Menu):
            return Menu(n)


q = FixedQueue(64)  # 최대 64개를 인큐할 수 있는 큐

while True:
    print(f'현재 데이터 개수 : {len(q)} / {q.capacity}')
    menu = select_menu()

    if menu == Menu.인큐:
        x = int(input('인큐할 데이터를 입력하세요 : '))
        try:
            q.enque(x)
        except FixedQueue.Full:
            print('큐가 가득 찼습니다.')

    elif menu == Menu.디큐:
        try:
            x = q.deque()
Ejemplo n.º 7
0
from enum import Enum
from fixed_queue import FixedQueue

Menu = Enum('Menu', ['enque', 'deque', 'peek', 'find', 'dump', 'exit'])


def select_menu() -> Menu:
    s = [f'({m.value}){m.name}' for m in Menu]
    while True:
        print(*s, sep='   ', end='')
        n = int(input(': '))
        if 1 <= n <= len(Menu):
            return Menu(n)


q = FixedQueue(64)  # 최대 64개의 데이터를 push 할 수 있는 스택

while True:
    print(f'현재 데이터 개수: {len(q)} / {q.capacity}')
    menu = select_menu()

    if menu == Menu.enque:
        x = int(input('데이터를 입력 하세요. : '))
        try:
            q.enque(x)
        except FixedQueue.Full:
            print('Queue is full..')

    elif menu == Menu.deque:
        try:
            x = q.deque()
Ejemplo n.º 8
0
Menu = Enum('Menu',['enque','deque','peek','find','count','clear','dump','exit'])

def select_menu() -> Menu:
    s = [f'({m.value}){m.name} 'for m in Menu]
    while True:
        print(*s,sep='',end='')

        n = int(input(': '))

        if 1 <= n <= 8:
            return Menu(n)

        break

q = FixedQueue(64)

while True:
    print(f'data size / capacity = {q.num} / {q.capacity}')
    menu = select_menu()

    if menu == Menu.enque:
        try:
            value = input('input enque value:')
            q.enque(value)

        except q.Full():
            print('Queue is full')

    elif menu == Menu.deque:
        try:
Menu = Enum('Menu', ['인큐', '디큐', '피크', '검색', '덤프', '종료'])  # 메뉴를 선언


def select_menu() -> Menu:
    # 메뉴 선택
    s = [f'({m.value}){m.name}' for m in Menu]

    while True:
        print(*s, sep='   ', end='')
        n = int(input(': '))

        if 1 <= n <= len(Menu):
            return Menu(n)


q = FixedQueue(64)  # 크기가 64인 스택

while True:
    print(f'현재 데이터 개수: {len(q)} / {q.capacity}')
    menu = select_menu()  # 메뉴 선택

    if menu == Menu.인큐:  # 인큐
        x = int(input('데이터를 입력하세요.: '))

        try:
            q.enque(x)
        except FixedQueue.Full:
            print('큐가 가득 차 있습니다')

    elif menu == Menu.디큐:  # 디큐
        try:
Ejemplo n.º 10
0
from fixed_queue import FixedQueue

Menu = Enum('Menu', ['エンキュー', 'デキュー', 'ピーク', '探索', 'ダンプ', '終了'])


def select_menu() -> Menu:
    """メニュー選択"""
    s = [f'({m.value}){m.name}' for m in Menu]
    while True:
        print(*s, sep='  ', end='')
        n = int(input(':'))
        if 1 <= n <= len(Menu):
            return Menu(n)


q = FixedQueue(64)  # 最大64個エンキューできるキュー

while True:
    print(f'現在のデータ数:{len(q)} / {q.capacity}')
    menu = select_menu()  # メニュー選択

    if menu == Menu.エンキュー:  # エンキュー
        x = int(input('データ:'))
        try:
            q.enque(x)
        except FixedQueue.Full:
            print('キューが満杯です。')

    elif menu == Menu.デキュー:  # デキュー
        try:
            x = q.deque()
Ejemplo n.º 11
0
def empty_queue():
    q = FixedQueue(0)

    return q
Ejemplo n.º 12
0
def test_dequeue():

    q = FixedQueue(3)

    q.enqueue(1)
    q.enqueue(2)
    q.enqueue(3)
    assert (q.dequeue() == 1)
    q.enqueue(4)
    assert (q.dequeue() == 2)
    q.enqueue(5)
    assert (q.dequeue() == 3)
    q.enqueue(6)
    assert (q.dequeue() == 4)
    q.enqueue(7)
    assert (q.dequeue() == 5)

    assert (len(q) == 2)
    q.dequeue()
    assert (len(q) == 1)
    q.dequeue()
    assert (len(q) == 0)

    with pytest.raises(IndexError):
        q.dequeue()
Ejemplo n.º 13
0
def new_queue():
    q = FixedQueue(2)

    return q