Skip to content

Commit d446f22

Browse files
committed
github action file and test file added
1 parent afe3926 commit d446f22

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

.github/workflows/ci.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: CI Workflow
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
test:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v2
18+
19+
- name: Set up Python
20+
uses: actions/setup-python@v2
21+
with:
22+
python-version: '3.9'
23+
24+
- name: Install dependencies
25+
run: |
26+
python -m pip install --upgrade pip
27+
pip install pytest streamlit
28+
29+
- name: Run tests
30+
run: |
31+
pytest _test.py

_test.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import pytest
2+
3+
# Function to test square
4+
def square(n):
5+
return n ** 2
6+
7+
# Function to test cube
8+
def cube(n):
9+
return n ** 3
10+
11+
# Function to test fifth power
12+
def fifth_power(n):
13+
return n ** 5
14+
15+
# Testing the square function
16+
def test_square():
17+
assert square(2) == 4, "Test Failed: Square of 2 should be 4"
18+
assert square(3) == 9, "Test Failed: Square of 3 should be 9"
19+
20+
# Testing the cube function
21+
def test_cube():
22+
assert cube(2) == 8, "Test Failed: Cube of 2 should be 8"
23+
assert cube(3) == 27, "Test Failed: Cube of 3 should be 27"
24+
25+
# Testing the fifth power function
26+
def test_fifth_power():
27+
assert fifth_power(2) == 32, "Test Failed: Fifth power of 2 should be 32"
28+
assert fifth_power(3) == 243, "Test Failed: Fifth power of 3 should be 243"
29+
30+
# Test for invalid input
31+
def test_invalid_input():
32+
with pytest.raises(TypeError):
33+
square("string")

0 commit comments

Comments
 (0)