Skip to content

Commit

Permalink
Merge pull request #17 from JordanWelsman/0.5-bugfixes
Browse files Browse the repository at this point in the history
To-do list complete. All tests pass. Merging now.
  • Loading branch information
JordanWelsman authored Mar 5, 2023
2 parents cc77709 + b3cf375 commit e80ca95
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 4 deletions.
2 changes: 1 addition & 1 deletion jutl/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Dunder attributes
__version__ = "0.5.0"
__version__ = "0.5.1"
__author__ = "Jordan Welsman"
__license__ = "MIT"
__copyright__ = "Copyright 2023 Jordan Welsman"
8 changes: 6 additions & 2 deletions jutl/datastructures/stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,17 @@ def pop(self) -> object:
"""
Removes the last added item from the stack.
"""
popped = self.top
self._stack.remove(self.top)
return self.top
return popped


@property
def top(self) -> object:
return self._stack[-1]
if len(self) > 0:
return self._stack[-1]
else:
raise IndexError("Stack is empty.")


def extend(self, other: Stack) -> Stack:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Arguments
git_name = "jutils"
pypi_name = "jutl"
version = "0.5.0" # update __init__.py
version = "0.5.1" # update __init__.py
python_version = ">=3.10"

# Long description from README.md
Expand Down
38 changes: 38 additions & 0 deletions test/datastructures/test_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,44 @@ def test_add(self):


class TestRobustness():
def test_push(self):
"""
Checks if pushing an
item to a stack works.
"""
stack = Stack()
stack.push(test_item)
assert len(stack) == 1
del(stack)

stack = Stack()
stack.push(test_item)
stack.push(test_item)
assert len(stack) == 2
del(stack)

stack = Stack()
stack.push(test_item, test_item, test_item)
assert len(stack) == 3
del(stack)

def test_pop(self):
"""
Checks if popping an
item from a stack works.
"""
stack = Stack()
stack.push(test_item, test_item, test_item)
assert stack.pop() == test_item
assert len(stack) == 2
del(stack)

stack = Stack()
stack.push(test_item)
assert stack.pop() == test_item
assert len(stack) == 0
del(stack)

def test_extend(self):
"""
Checks if the extend
Expand Down

0 comments on commit e80ca95

Please sign in to comment.