Skip to content

Commit dfe829e

Browse files
committed
Testing Workflow 🐍🧪
1 parent b9c0a13 commit dfe829e

File tree

3 files changed

+109
-0
lines changed

3 files changed

+109
-0
lines changed

.github/workflows/tests.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# This workflow installs the required dependencies, and runs tests with pytest over multiple versions of Python.
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
3+
4+
name: Tests
5+
6+
on:
7+
push:
8+
branches: [ main ]
9+
pull_request:
10+
branches: [ main ]
11+
12+
jobs:
13+
build:
14+
15+
runs-on: ubuntu-latest
16+
strategy:
17+
matrix:
18+
# Python Versions to Test
19+
# 3.9 for built-in `list` static typing, TODO maybe redo the code to support older versions?
20+
python-version: [3.9]
21+
22+
steps:
23+
- uses: actions/checkout@v2
24+
- name: Set Up Python ${{ matrix.python-version }}
25+
uses: actions/setup-python@v2
26+
with:
27+
python-version: ${{ matrix.python-version }}
28+
29+
# Install required dependencies with `requirements.txt`
30+
- name: Install Dependencies
31+
run: |
32+
python -m pip install --upgrade pip
33+
pip install flake8 pytest
34+
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
35+
36+
# Test with PyTest -Verbose
37+
- name: Test w/PyTest
38+
run: |
39+
pytest -v

pytest.ini

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[pytest]
2+
minversion = 6.0
3+
addopts = -ra -q
4+
testpaths =
5+
src

src/test_algorithms.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Functions that test the algorithm implementations, for `pytest` #
2+
3+
from algorithms.selection_sort import selection_sort
4+
from algorithms.insertion_sort import insertion_sort
5+
from algorithms.bubble_sort import bubble_sort
6+
from algorithms.quick_sort import quick_sort
7+
from algorithms.merge_sort import merge_sort
8+
from algorithms.gnome_sort import gnome_sort
9+
from algorithms.shell_sort import shell_sort
10+
from algorithms.comb_sort import comb_sort
11+
from algorithms.heap_sort import heap_sort
12+
13+
14+
def test_selection_sort():
15+
arr: list[int] = [ 5, 3, 2, 1, 5 ]
16+
selection_sort(arr)
17+
assert arr == [ 1, 2, 3, 5, 5 ]
18+
19+
20+
def test_insertion_sort():
21+
arr: list[int] = [ 5, 3, 2, 1, 5 ]
22+
insertion_sort(arr)
23+
assert arr == [ 1, 2, 3, 5, 5 ]
24+
25+
26+
def test_bubble_sort():
27+
arr: list[int] = [ 5, 3, 2, 1, 5 ]
28+
bubble_sort(arr)
29+
assert arr == [ 1, 2, 3, 5, 5 ]
30+
31+
32+
def test_quick_sort():
33+
arr: list[int] = [ 5, 3, 2, 1, 5 ]
34+
quick_sort(arr)
35+
assert arr == [ 1, 2, 3, 5, 5 ]
36+
37+
38+
def test_merge_sort():
39+
arr: list[int] = [ 5, 3, 2, 1, 5 ]
40+
merge_sort(arr)
41+
assert arr == [ 1, 2, 3, 5, 5 ]
42+
43+
44+
def test_gnome_sort():
45+
arr: list[int] = [ 5, 3, 2, 1, 5 ]
46+
gnome_sort(arr)
47+
assert arr == [ 1, 2, 3, 5, 5 ]
48+
49+
50+
def test_shell_sort():
51+
arr: list[int] = [ 5, 3, 2, 1, 5 ]
52+
shell_sort(arr)
53+
assert arr == [ 1, 2, 3, 5, 5 ]
54+
55+
56+
def test_comb_sort():
57+
arr: list[int] = [ 5, 3, 2, 1, 5 ]
58+
comb_sort(arr)
59+
assert arr == [ 1, 2, 3, 5, 5 ]
60+
61+
62+
def test_heap_sort():
63+
arr: list[int] = [ 5, 3, 2, 1, 5 ]
64+
heap_sort(arr)
65+
assert arr == [ 1, 2, 3, 5, 5 ]

0 commit comments

Comments
 (0)