I need to generate unit tests for a mathematical equation such as a= (b+c)* d and boolean expressions.Is there any methodology and/or utility to achieve this?
Asked
Active
Viewed 1,038 times
-1
-
I'm sure there is.. but StackOverflow isn't a place for such a general shopping query. – user2864740 Dec 17 '15 at 07:05
-
Start here - https://en.wikipedia.org/wiki/Unit_testing – Enigmativity Dec 17 '15 at 07:14
-
What do you want to test about these equations ? That they parse correctly ? That they evaluate correctly ? Symbolic transformations ? ... – Dec 17 '15 at 13:57
-
These are requirements. need to black box test the code written against them – user3048305 Dec 22 '15 at 08:24
1 Answers
1
Note:
Because of the vagueness of the question i'm going to assume the programming language one can use is variable. In this case Python uses a object oriented approach to unittesting.
Answer:
For most unittest problems in python, you can use the standard unittest library. An example case for the given equation can be:
import unittest
def test_equation(b,c,d):
return (b+c) * d
class testEquation(unittest.TestCase):
def setUp(self):
pass
def testEquationInput(self):
b = 5
c = 4
d = 10
self.assertEqual(test_equation(b,c,d), 90)
if __name__ == "__main__":
unittest.main()
you can execute this code with:
python unittest test_module.py
or if you write a directory with unittests:
python -m unittest discover /path/to/test/directory

folkert kevelam
- 134
- 5