From 8d9526f8bbaebd49c7ee2395821ef5523368592c Mon Sep 17 00:00:00 2001
From: brodriguez8774 <brodriguez8774@gmail.com>
Date: Mon, 16 Sep 2019 13:24:10 -0400
Subject: [PATCH] Implement full stack class

---
 resources/stack.py       | 46 +++++++++++++++++++++++++++
 tests/resources/stack.py | 67 ++++++++++++++++++++++++++++++++++++++--
 2 files changed, 111 insertions(+), 2 deletions(-)

diff --git a/resources/stack.py b/resources/stack.py
index 41d86bd..ee63fdd 100644
--- a/resources/stack.py
+++ b/resources/stack.py
@@ -13,3 +13,49 @@ class Stack():
     """
     Custom stack implementation.
     """
+    def __init__(self):
+        self._data_ = []
+
+    def push(self, value):
+        """
+        Adds new item to stack.
+        :param value: Item to add.
+        """
+        self._data_.append(value)
+
+    def pop(self):
+        """
+        Remove most recent item from stack.
+        :return: Most recent item added to stack.
+        """
+        if self.size() > 0:
+            return self._data_.pop()
+        else:
+            return None
+
+    def is_empty(self):
+        """
+        Checks if stack is empty.
+        :return: Boolean indicating if empty.
+        """
+        if self.size() == 0:
+            return True
+        else:
+            return False
+
+    def top(self):
+        """
+        Gets top element of stack, without removing item.
+        :return: Top element of stack.
+        """
+        if self.size() > 0:
+            return self._data_[self.size() - 1]
+        else:
+            return None
+
+    def size(self):
+        """
+        Gets count of elements within stack.
+        :return: Count of elements in stack.
+        """
+        return len(self._data_)
diff --git a/tests/resources/stack.py b/tests/resources/stack.py
index 33dd055..990eea5 100644
--- a/tests/resources/stack.py
+++ b/tests/resources/stack.py
@@ -23,7 +23,70 @@ class TestMain(unittest.TestCase):
         self.assertTrue(isinstance(self.test_stack, Stack))
 
     def test_push(self):
-        pass
+        # Test initial state.
+        self.assertEqual(len(self.test_stack._data_), 0)
+
+        # Test adding first element.
+        self.test_stack.push(4)
+        self.assertEqual(len(self.test_stack._data_), 1)
+        self.assertEqual(self.test_stack._data_[0], 4)
+
+        # Test adding second element.
+        self.test_stack.push('testing')
+        self.assertEqual(len(self.test_stack._data_), 2)
+        self.assertEqual(self.test_stack._data_[0], 4)
+        self.assertEqual(self.test_stack._data_[1], 'testing')
+
+        # Works with 0, 1, and 2 elements. Assuming it works for all further n+1 elements.
 
     def test_pop(self):
-        pass
+        # Test with zero elements.
+        self.assertIsNone(self.test_stack.pop())
+
+        # Test with one element.
+        self.test_stack.push(4)
+        self.assertEqual(self.test_stack.pop(), 4)
+
+        # Test with two elements.
+        self.test_stack.push(4)
+        self.test_stack.push('testing')
+        self.assertEqual(self.test_stack.pop(), 'testing')
+        self.assertEqual(self.test_stack.pop(), 4)
+
+        # Works with 0, 1, and 2 elements. Assuming it works for all further n+1 elements.
+
+    def test_is_empty(self):
+        # Test with zero elements.
+        self.assertTrue(self.test_stack.is_empty())
+
+        # Test with more than zero elements.
+        self.test_stack.push('')
+        self.assertFalse(self.test_stack.is_empty())
+
+    def test_top(self):
+        # Test with zero elements.
+        self.assertIsNone(self.test_stack.top())
+
+        # Test with one element.
+        self.test_stack.push(5)
+        self.assertEqual(self.test_stack.top(), 5)
+
+        # Test with two elements.
+        self.test_stack.push('testing')
+        self.assertEqual(self.test_stack.top(), 'testing')
+
+        # Works with 0, 1, and 2 elements. Assuming it works for all further n+1 elements.
+
+    def test_size(self):
+        # Test with zero elements.
+        self.assertEqual(self.test_stack.size(), 0)
+
+        # Test with one element.
+        self.test_stack.push(6)
+        self.assertEqual(self.test_stack.size(), 1)
+
+        # Test with two elements.
+        self.test_stack.push('testing')
+        self.assertEqual(self.test_stack.size(), 2)
+
+        # Works with 0, 1, and 2 elements. Assuming it works for all further n+1 elements.
-- 
GitLab