Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9555b75

Browse filesBrowse files
authored
Merge pull request #13 from codeasarjun/testing
testing examples has been added
2 parents 548eb9d + 477127e commit 9555b75
Copy full SHA for 9555b75

File tree

Expand file treeCollapse file tree

3 files changed

+41
-0
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+41
-0
lines changed

‎21-testing-debugging/README.md

Copy file name to clipboard
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
This repo contains basic examples for testing and debugging in Python.
2+
3+
## Files
4+
5+
- **`basic_testing.py`**: Contains a simple function and tests for it using Python's `unittest` framework.
6+
- **`debugging_example.py`**: Demonstrates common errors and issues in code for practice in debugging.
7+
8+
## Running the Code
9+
10+
### Testing
11+
12+
To run the tests in `basic_testing.py`, use the following command:
13+
14+
```bash
15+
python basic_testing.py
16+
```

‎21-testing-debugging/basic_testing.py

Copy file name to clipboard
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import unittest
2+
3+
def add(a, b):
4+
return a + b
5+
6+
class TestMathFunctions(unittest.TestCase):
7+
8+
def test_add(self):
9+
self.assertEqual(add(1, 2), 3)
10+
self.assertEqual(add(-1, 1), 0)
11+
self.assertEqual(add(-1, -1), -2)
12+
13+
if __name__ == "__main__":
14+
unittest.main()
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
def multiply(a, b):
2+
# intentional bug: incorrect operation
3+
return a + b
4+
5+
def divide(a, b):
6+
# intentional bug: division by zero
7+
return a / b
8+
9+
if __name__ == "__main__":
10+
print(multiply(2, 3)) # expected output: 6
11+
print(divide(10, 0)) # expected to raise ZeroDivisionError

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.