start unittest for expression and fraction
This commit is contained in:
parent
8e86220b50
commit
49b224bedc
53
test/test_expression.py
Normal file
53
test/test_expression.py
Normal file
@ -0,0 +1,53 @@
|
||||
#!/usr/bin/env python
|
||||
# encoding: utf-8
|
||||
|
||||
|
||||
|
||||
import unittest
|
||||
|
||||
from pymath.expression import Expression
|
||||
from pymath.fraction import Fraction
|
||||
from pymath.generic import first_elem
|
||||
|
||||
|
||||
class TestExpression(unittest.TestCase):
|
||||
"""Testing functions from pymath.expression"""
|
||||
|
||||
def test_init_from_exp(self):
|
||||
pass
|
||||
|
||||
def test_init_from_exp(self):
|
||||
pass
|
||||
|
||||
def test_infix_tokens(self):
|
||||
pass
|
||||
|
||||
def test_postfix_tokens(self):
|
||||
pass
|
||||
|
||||
def test_doMath(self):
|
||||
ops = [\
|
||||
{"op": ("+", 1 , 2), "res" : 3}, \
|
||||
{"op": ("-", 1 , 2), "res" : -1}, \
|
||||
{"op": ("*", 1 , 2), "res" : 2}, \
|
||||
{"op": ("/", 1 , 2), "res" : Fraction(1,2)}, \
|
||||
{"op": ("^", 1 , 2), "res" : 1}, \
|
||||
]
|
||||
for op in ops:
|
||||
res = first_elem(Expression.doMath(*op["op"]))
|
||||
self.assertAlmostEqual(res, op["res"])
|
||||
|
||||
def test_isNumber(self):
|
||||
pass
|
||||
|
||||
def test_isOperator(self):
|
||||
pass
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
|
||||
# -----------------------------
|
||||
# Reglages pour 'vim'
|
||||
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
|
||||
# cursor: 16 del
|
65
test/test_fraction.py
Normal file
65
test/test_fraction.py
Normal file
@ -0,0 +1,65 @@
|
||||
#!/usr/bin/env python
|
||||
# encoding: utf-8
|
||||
|
||||
import unittest
|
||||
|
||||
from pymath.fraction import Fraction
|
||||
|
||||
class TestFraction(unittest.TestCase):
|
||||
"""Testing functions from pymath.Fraction"""
|
||||
|
||||
def setUp(self):
|
||||
self.listFrom = [Fraction(1,3), 1]
|
||||
self.listAgainst = [ Fraction(1,3), \
|
||||
Fraction(2,3), \
|
||||
Fraction(4,5), \
|
||||
Fraction(-1, 3), \
|
||||
Fraction(1,-3), \
|
||||
Fraction(0,2), \
|
||||
1,
|
||||
]
|
||||
|
||||
def test_add(self):
|
||||
ans = [[Fraction(2, 3), 1, Fraction(17, 15), 0, 0, Fraction(1,3), Fraction(4,3)], \
|
||||
[Fraction(4,3), Fraction(5,3), Fraction(9,3), Fraction(2,3), Fraction(2,3), 1, 0] \
|
||||
]
|
||||
|
||||
for (i, f1) in enumerate(self.listFrom):
|
||||
for (j, f2) in enumerate(self.listAgainst):
|
||||
res = f1 + f2
|
||||
print(res)
|
||||
self.assertAlmostEqual(res[-1], ans[i][j])
|
||||
|
||||
|
||||
def test_radd(self):
|
||||
pass
|
||||
|
||||
def test_sub(self):
|
||||
pass
|
||||
|
||||
def test_rsub(self):
|
||||
pass
|
||||
|
||||
def test_neg(self):
|
||||
pass
|
||||
|
||||
def test_mul(self):
|
||||
pass
|
||||
|
||||
def test_truediv(self):
|
||||
pass
|
||||
|
||||
def test_lt(self):
|
||||
pass
|
||||
|
||||
def test_le(self):
|
||||
pass
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
# -----------------------------
|
||||
# Reglages pour 'vim'
|
||||
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
|
||||
# cursor: 16 del
|
Loading…
Reference in New Issue
Block a user