Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import unittest from PythonLabCode.LabCode.Stack import Stack import PythonLabCode.LabCode.StackFullException as StackFullException import PythonLabCode.LabCode.StackEmptyException as StackEmptyException class MyTestCase ( unittest . TestCase ) : def test _

import unittest
from PythonLabCode.LabCode.Stack import Stack
import PythonLabCode.LabCode.StackFullException as StackFullException
import PythonLabCode.LabCode.StackEmptyException as StackEmptyException
class MyTestCase(unittest.TestCase):
def test_create_stack(self):
# ARRANGE
my_stack = Stack(1)
# ACT
actual = my_stack.is_empty()
# ASSERT
self.assertTrue(actual)
def test_is_empty_true(self):
# ARRANGE
my_stack = Stack(1)
# ACT
actual = my_stack.is_empty()
# ASSERT
self.assertTrue(actual)
def test_is_empty_false(self):
# ARRANGE
my_stack = Stack(2)
item = "StackEmpty"
# ACT
my_stack.push(item)
actual = my_stack.is_empty()
# ASSERT
self.assertFalse(actual)
def test_is_full_True(self):
# ARRANGE
my_stack = Stack(1)
item = "StackItem"
# ACT
my_stack.push(item +"1")
actual = my_stack.is_full()
# ASSERT
self.assertTrue(actual)
def test_is_full_False(self):
# ARRANGE
my_stack = Stack(2)
item = "StackItem"
# ACT
my_stack.push(item +"1")
actual = my_stack.is_full()
# ASSERT
self.assertFalse(actual)
def test_push_stack(self):
# ARRANGE
my_stack = Stack(2)
item = "StackItem"
expected = "StackItem2"
# ACT
my_stack.push(item +"1")
my_stack.push(item +"2")
actual = my_stack.peek()
# ASSERT
self.assertEqual(expected, actual)
def test_push_full_stack(self):
# ARRANGE
my_stack = Stack(1)
item = "StackItem"
# ACT
my_stack.push(item +"1")
# ASSERT
with self.assertRaises(StackFullException):
my_stack.push(item);
def test_pop_stack(self):
# ARRANGE
my_stack = Stack(2)
item = "StackItem"
expected = "StackItem1"
my_stack.push(item+"1")
# ACT
actual = my_stack.pop()
# ASSERT
self.assertEqual(expected, actual)
def test_stack_size_zero(self):
# ARRANGE
my_stack = Stack(2)
expected =0
# ACT
actual = my_stack.size()
# ASSERT
self.assertEqual(expected, actual)
def test_stack_size_non_zero(self):
# ARRANGE
my_stack = Stack(2)
item = "StackItem"
expected =1
# ACT
my_stack.push(item +"1")
actual = my_stack.size()
# ASSERT
self.assertEqual(expected, actual)
def test_pop_empty_stack(self):
# ARRANGE
my_stack = Stack(1)
# ACT
# ASSERT
with self.assertRaises(StackEmptyException):
my_stack.pop()
def test_peek_stack(self):
# ARRANGE
my_stack = Stack(1)
item = "StackItem"
# ACT
my_stack.push(item)
expected = item
actual = my_stack.peek()
# ASSERT
self.assertEqual(expected, actual)
def test_peek_stack_twice(self):
# ARRANGE
my_stack = Stack(1)
item = "StackItem"
# ACT
my_stack.push(item)
expected = item
my_stack.peek()
actual = my_stack.peek()
# ASSERT
self.assertEqual(expected, actual)
def test_peek_empty_stack(self):
# ARRANGE
my_stack = Stack(1)
# ACT
# ASSERT
with self.assertRaises(StackEmptyException):
my_stack.peek()
def test_print_stack_up(self):
# ARRANGE
my_stack = Stack(2)
item = "StackItem"
expected = "StackItem1
StackItem2
"
# ACT
my_stack.push(item +"1")
my_stack.push(item +"2")
actual = my_stack.print_stack_up()
# ASSERT
self.assertEqual(expected, actual)
def test_print_stack_up_empty_stack(self):
# ARRANGE
my_stack = Stack(1)
# ACT
# ASSERT
with self.assertRaises(StackEmptyException):
my_stack.print_stack_up()
if __name__=='__main__':
unittest.main()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Multidimensional Array Data Management In Databases

Authors: Florin Rusu

1st Edition

1638281483, 978-1638281481

More Books

Students also viewed these Databases questions

Question

What are the need and importance of training ?

Answered: 1 week ago

Question

What is job rotation ?

Answered: 1 week ago

Question

The company openly shares plans and information with employees.

Answered: 1 week ago