예제 #1
0
    def test_empty(self):
        s = FixedStack(10)
        self.assertTrue(s.empty())

        s.push(randint(0, 100))
        self.assertFalse(s.empty())
        
        s.pop()
        self.assertTrue(s.empty())
예제 #2
0
    def test_underflow(self):
        s = FixedStack(10)
        with self.assertRaises(Exception):
            s.pop()

        s.push(0)
        s.pop()
        with self.assertRaises(Exception):
            s.pop()
예제 #3
0
    def test_overflow(self):
        s = FixedStack(0)
        with self.assertRaises(Exception):
            s.push(0)

        s = FixedStack(1)
        s.push(0)
        with self.assertRaises(Exception):
            s.push(0)
예제 #4
0
        print(*s, sep=' ', end='')
        n = int(input(": "))
        if 1 <= n <= len(Menu):
            return Menu(n)


s = FixedStack(64)

while True:
    print(f'current number of data: {len(s)} / {s.capacity}')
    menu = select_menu()

    if menu == Menu.Push:
        x = int(input('value: '))
        try:
            s.push(x)
        except FixedStack.Full:
            print('stack is full')

    elif menu == Menu.Pop:
        try:
            x = s.pop()
            print(f'popped data: {x}')
        except FixedStack.Empty:
            print("stack is empty")

    elif menu == Menu.Peek:
        try:
            x = s.peek()
            print(f'peeked data: {x}')
        except FixedStack.Empty:
예제 #5
0
        print(*s,sep=' ',end='')
        n = int(input(": "))
        if 1<= n <=6:
            return Menu(n)


s = FixedStack(64)

while True:
    print("현재 데이터 갯수: {} / {}".format(len(s),s.capacity))
    menu = select_menu()

    if menu == menu.푸시:
        value = int(input("푸시 데이터:"))
        try:
            s.push(value)
        except FixedStack.Full:
            print('스택이 꽉 차 있습니다.')

    elif menu == menu.팝:
        try:
            x = s.pop()
            print(f'팝 데이터는 {x}입니다.')
        except FixedStack.Empty:
            print('스택이 비어있습니다.')

    elif menu == menu.피크:
        try:
            x = s.peek()
            print(f'피크한 데이터는 {x}입니다.')
        except FixedStack.Empty: