Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!