Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Run Tests

on:
push:
branches: [ master, main ]
pull_request:
branches: [ master, main ]

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11']

steps:
- uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt

- name: Run tests with pytest
run: |
pytest tests/ -v --cov=Examples --cov-report=term-missing

- name: Run tests with unittest
run: |
python -m unittest discover -s tests -p "test_*.py" -v
134 changes: 134 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
PIPFILE.lock

# PyInstaller
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
Pipfile.lock

# PEP 582
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# IDEs
.vscode/
.idea/
*.swp
*.swo
*~

# OS
.DS_Store
Thumbs.db
5 changes: 3 additions & 2 deletions Examples/calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,6 @@ def again(cls):
else:
Calc.again()

# Call calculate() outside of the function
Calc.calculate()
# Call calculate() outside of the function only if run directly
if __name__ == "__main__":
Calc.calculate()
28 changes: 14 additions & 14 deletions Examples/circular_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,22 @@ def Display(self):
print(self.__items[i])

#This is the main program illustrating the use of the queue
if __name__ == "__main__":
myQ = Queue() #Instantiate a new queue
myQ.deQueue() #Should give -1 error

myQ = Queue() #Instantiate a new queue
myQ.deQueue() #Should give -1 error
myQ.enQueue(1) #Add some data to the queue
myQ.enQueue(2)
myQ.enQueue(3)
myQ.enQueue(4)
myQ.enQueue(5)

myQ.enQueue(1) #Add some data to the queue
myQ.enQueue(2)
myQ.enQueue(3)
myQ.enQueue(4)
myQ.enQueue(5)
#This one should fail, queue full
myQ.enQueue(6)

#This one should fail, queue full
myQ.enQueue(6)
myQ.Display()

myQ.Display()
x = myQ.deQueue() #Remove 2 items from the queue
x = myQ.deQueue()

x = myQ.deQueue() #Remove 2 items from the queue
x = myQ.deQueue()

myQ.Display()
myQ.Display()
34 changes: 20 additions & 14 deletions Examples/stack.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
"""
Stack Implementation

# Stack
* A stack is a group of elements stored in LIFO (Last In First Out) order. The element which is stored as a last element into the stack
* will be the first element to be removed from the stack. The stack is used by operating system to save the program execution environment.
* basically there are five operations we are performing on stack.
* Push operation: Inserting element into stack
* Pop operation: Removing element from stack
* Search operation: Searching an element in the stack
* Peep/Peak operation: Returning the topmost element of the stack without deleting the element
* Empty stack operation: Returning stack is empty or not
A stack is a group of elements stored in LIFO (Last In First Out) order. The element which is stored as a last element into the stack
will be the first element to be removed from the stack. The stack is used by operating system to save the program execution environment.

Basically there are five operations we are performing on stack:
- Push operation: Inserting element into stack
- Pop operation: Removing element from stack
- Search operation: Searching an element in the stack
- Peep/Peak operation: Returning the topmost element of the stack without deleting the element
- Empty stack operation: Returning stack is empty or not
"""


# Stack class
Expand All @@ -20,7 +23,7 @@ def isempty(self):
return self.st == []

# Inserting an element in the list
def push(self):
def push(self, element):
self.st.append(element)

# Removing the last element from the list
Expand All @@ -44,21 +47,24 @@ def search(self, element):
try:
num = self.st.index(element)
return len(self.st) - num
except valueError:
return 2
except ValueError:
return -1

# Display the operations
def display(self):
return self.st


#### This is a basic Stack data structure usin OOP programming in python.
A stack is a data structure which uses a LIFO(Last In First Out) order to preform operations.
"""
This is a basic Stack data structure using OOP programming in python.
A stack is a data structure which uses a LIFO(Last In First Out) order to perform operations.
Last In First Out means that the last item to be added to the stack will be the first one to be taken out
It is used in many cases. For example internet search history and creating programming languages.
This program is a bare bones version but can be improved and added to
Python implements a Stack by using a list.
The list contains all the information held in the stack and we use python list functions within our stack methods.
"""

# Example 2
class Stack(object):

Expand Down
29 changes: 28 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,31 @@
# Learning-Object-Oriented-Python

![](https://www.codetriage.com/josharsh/learning-object-oriented-python/badges/users.svg)
This repository walks you through the Object Oriented Programming in python. Illustrates real world examples, working codes and going about finding a coding solution.
![Tests](https://github.com/josharsh/OPython-Init/workflows/Run%20Tests/badge.svg)

This repository walks you through the Object Oriented Programming in python. Illustrates real world examples, working codes and going about finding a coding solution.

## 🧪 Testing Framework

This repository includes a comprehensive test suite to ensure code quality and help learners understand Test-Driven Development (TDD).

### Running Tests

```bash
# Install dependencies
pip install -r requirements.txt

# Run all tests
python -m unittest discover -s tests -p "test_*.py" -v

# Or use pytest
pytest tests/ -v

# Run with coverage
pytest tests/ -v --cov=Examples --cov-report=html
```

### CI/CD

All tests run automatically on every push and pull request via GitHub Actions. See `.github/workflows/tests.yml` for details.

Loading