master > master: code py - refactoring
- umbenennungen - verbesseungen der Darstellungen - enums zur beseren Steuerung der versch. Modi - refactoring des Algorithmus - Verwendung von tabulator
This commit is contained in:
0
code/python/tests/tests_stacks/__init__.py
Normal file
0
code/python/tests/tests_stacks/__init__.py
Normal file
15
code/python/tests/tests_stacks/conftest.py
Normal file
15
code/python/tests/tests_stacks/conftest.py
Normal file
@@ -0,0 +1,15 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
# IMPORTS
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
from pytest import mark;
|
||||
from pytest import fixture;
|
||||
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
# FIXTURES
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
#
|
||||
63
code/python/tests/tests_stacks/test_stack.py
Normal file
63
code/python/tests/tests_stacks/test_stack.py
Normal file
@@ -0,0 +1,63 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
# IMPORTS
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
from contextlib import nullcontext as does_not_raise
|
||||
import pytest;
|
||||
from pytest import mark;
|
||||
from unittest import TestCase;
|
||||
|
||||
from src.stacks.stack import Stack;
|
||||
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
# 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 pytest.raises(Exception):
|
||||
stack.pop();
|
||||
stack.pop();
|
||||
stack.pop();
|
||||
stack.pop();
|
||||
Reference in New Issue
Block a user