Skip to content

Commit de83a96

Browse files
committed
Add initial unit tests for calculator.py
1 parent 151aa4e commit de83a96

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

python-calculator/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,8 @@ Additionally, this can be ran from your Python IDE of choice such as PyCharm, ID
1717

1818
See below an image of the script in action:
1919
![Image of Calculator](https://github.com/markusewalker/Misc-Python-Scripts/blob/main/python-calculator/calculator.png)
20+
21+
### Testing
22+
Included is `calculator_unittest.py` to check for correctness. The tests provide few, basic tests to verify the addition, subtraction, multiplication and division functions are working properly. To run in the command-line, run the following command:
23+
24+
**python3 -m unittest calculator_unittest.py**

python-calculator/calculator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python
22

33
# Authored By: Markus Walker
4-
# Date Modified: 1/28/22
4+
# Date Modified: 1/29/22
55
#
66
# Descrption: Simple calculator written in Python 3. It provides the following
77
# operations:
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env python
2+
3+
# Authored By: Markus Walker
4+
# Date Modified: 1/30/22
5+
#
6+
# Descrption: Unit test for the calculator.py script. Several unit tests
7+
# against the addition, subtraction, multiplication and division functions
8+
# of the calculator.py script.
9+
from calculator import *
10+
import unittest
11+
from unittest.mock import patch
12+
13+
class TestCalculator(unittest.TestCase):
14+
def test_addition(self):
15+
self.assertEqual(addition(20,10), 30.0)
16+
self.assertNotEqual(addition(20,10), 10.0)
17+
18+
def test_subtraction(self):
19+
self.assertEqual(subtraction(20,10), 10.0)
20+
self.assertNotEqual(subtraction(20,10), 30.0)
21+
22+
def test_multiplication(self):
23+
self.assertEqual(multiplication(20,10), 200.0)
24+
self.assertNotEqual(multiplication(20,10), 2.0)
25+
26+
def test_division(self):
27+
self.assertEqual(division(20,10), 2.0)
28+
self.assertNotEqual(division(20,10), 200.0)
29+
30+
if __name__ == "__main__":
31+
unittest.main()

0 commit comments

Comments
 (0)