ads2_2022/code/python/tests/tests_stacks/test_stack.py

61 lines
1.8 KiB
Python
Raw Normal View History

2022-04-18 19:16:28 +02:00
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# IMPORTS
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
from tests.thirdparty.unit import *;
2022-04-18 19:16:28 +02:00
2022-06-10 12:28:00 +02:00
from src.models.stacks import Stack;
2022-04-18 19:16:28 +02:00
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Fixtures
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def format_data_for_display(data):
return [ '{given_name} {family_name}: {title}'.format(**row) for row in data ];
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Test stack
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@mark.usefixtures('test')
def test_stack_initialisation(test: TestCase):
stack = Stack();
test.assertEqual(len(stack), 0);
@mark.usefixtures('test')
def test_stack_push(test: TestCase):
stack = Stack();
test.assertEqual(len(stack), 0);
stack.push('hallo');
test.assertEqual(len(stack), 1);
stack.push('welt');
test.assertEqual(len(stack), 2);
stack.push('!');
test.assertEqual(len(stack), 3);
@mark.usefixtures('test')
def test_stack_no_error(test: TestCase):
stack = Stack();
stack.push('hallo');
stack.push('welt');
stack.push('!');
with does_not_raise():
stack.pop();
stack.pop();
stack.pop();
@mark.usefixtures('test')
def test_stack_error_po(test: TestCase):
stack = Stack();
stack.push('hallo');
stack.push('welt');
stack.push('!');
with assert_raises(Exception):
2022-04-18 19:16:28 +02:00
stack.pop();
stack.pop();
stack.pop();
stack.pop();