Last active
March 26, 2019 13:11
-
-
Save ivanleoncz/50f2f70268e209280ee90fe184033ecb to your computer and use it in GitHub Desktop.
Example of Unit Testing.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
class Calc: | |
""" Arithmetic Operations for two numbers, per function. """ | |
def add(self, n1, n2): | |
""" Performs addition of two numbers. """ | |
time.sleep(5) # intentional sleep for measuring time consumed | |
return n1 + n2 | |
def sub(self, n1, n2): | |
""" Performs subtraction of two numbers. """ | |
return n1 - n2 | |
def mult(self, n1, n2): | |
""" Performs multiplication of two numbers. """ | |
return n1 * n2 | |
def div(self, n1, n2): | |
""" Performs division of two numbers. """ | |
return n1 // n2 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import calculation | |
import unittest | |
calc = calculation.Calc() | |
class Probe(unittest.TestCase): | |
""" Probe for testing Calc class and its methods. """ | |
def test_add(self): | |
""" Testing add() method from Calc class. """ | |
self.assertEqual(calc.add(3, 3), 6) | |
def test_sub(self): | |
""" Testing sub() method from Calc class. """ | |
self.assertEqual(calc.sub(3, 3), 0) | |
def test_mult(self): | |
""" Testing mult() method from Calc class. """ | |
self.assertEqual(calc.mult(3, 3), 9) | |
def test_div(self): | |
""" Testing div() method from Calc class. """ | |
self.assertEqual(calc.div(3, 3), 1) | |
if __name__ == "__main__": | |
unittest.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment