Remove unittest module in test_random_expression
This commit is contained in:
parent
2b98d0e364
commit
1404c6fa35
@ -2,103 +2,88 @@
|
|||||||
# encoding: utf-8
|
# encoding: utf-8
|
||||||
|
|
||||||
|
|
||||||
import unittest
|
|
||||||
|
|
||||||
from pymath.calculus.random_expression import RdExpression
|
from pymath.calculus.random_expression import RdExpression
|
||||||
|
|
||||||
|
|
||||||
class TestRandomExpression(unittest.TestCase):
|
def test_only_form():
|
||||||
"""Testing functions from pymath.calculus.random_expression"""
|
|
||||||
|
|
||||||
def test_only_form(self):
|
|
||||||
form = "{a} + 2"
|
form = "{a} + 2"
|
||||||
rdExp = RdExpression(form)
|
rdExp = RdExpression(form)
|
||||||
|
|
||||||
self.assertEqual(rdExp._letters, {'a'})
|
assert rdExp._letters == {'a'}
|
||||||
self.assertEqual(rdExp._2replaced, {'a'})
|
assert rdExp._2replaced == {'a'}
|
||||||
|
|
||||||
rdExp()
|
rdExp()
|
||||||
self.assertEqual(set(rdExp._gene_varia.keys()), {'a'})
|
assert set(rdExp._gene_varia.keys()) == {'a'}
|
||||||
self.assertEqual(set(rdExp._gene_2replaced.keys()), {'a'})
|
assert set(rdExp._gene_2replaced.keys()) == {'a'}
|
||||||
|
|
||||||
def test_only_form_calc(self):
|
def test_only_form_calc():
|
||||||
form = "{a+b} + 2"
|
form = "{a+b} + 2"
|
||||||
rdExp = RdExpression(form)
|
rdExp = RdExpression(form)
|
||||||
|
|
||||||
self.assertEqual(rdExp._letters, {'a', 'b'})
|
assert rdExp._letters, {'a' == 'b'}
|
||||||
self.assertEqual(rdExp._2replaced, {'a+b'})
|
assert rdExp._2replaced == {'a+b'}
|
||||||
|
|
||||||
rdExp()
|
rdExp()
|
||||||
self.assertEqual(set(rdExp._gene_varia.keys()), {'a', 'b'})
|
assert set(rdExp._gene_varia.keys()), {'a' == 'b'}
|
||||||
self.assertEqual(set(rdExp._gene_2replaced.keys()), {'a+b'})
|
assert set(rdExp._gene_2replaced.keys()) == {'a+b'}
|
||||||
|
|
||||||
def test_only_form_cond(self):
|
def test_only_form_cond():
|
||||||
form = "{a} + 2"
|
form = "{a} + 2"
|
||||||
cond = ["{a} == 3"]
|
cond = ["{a} == 3"]
|
||||||
rdExp = RdExpression(form, cond)
|
rdExp = RdExpression(form, cond)
|
||||||
|
|
||||||
self.assertEqual(rdExp._letters, {'a'})
|
assert rdExp._letters == {'a'}
|
||||||
self.assertEqual(rdExp._2replaced, {'a'})
|
assert rdExp._2replaced == {'a'}
|
||||||
|
|
||||||
rdExp()
|
rdExp()
|
||||||
self.assertEqual(set(rdExp._gene_varia.keys()), {'a'})
|
assert set(rdExp._gene_varia.keys()) == {'a'}
|
||||||
self.assertEqual(set(rdExp._gene_2replaced.keys()), {'a'})
|
assert set(rdExp._gene_2replaced.keys()) == {'a'}
|
||||||
|
|
||||||
self.assertEqual(rdExp._gene_varia['a'], 3)
|
assert rdExp._gene_varia['a'] == 3
|
||||||
|
|
||||||
def test_only_form_conds(self):
|
def test_only_form_conds():
|
||||||
form = "{a} + 2"
|
form = "{a} + 2"
|
||||||
cond = ["{a} in list(range(5))", "{a} % 2 == 1"]
|
cond = ["{a} in list(range(5))", "{a} % 2 == 1"]
|
||||||
rdExp = RdExpression(form, cond)
|
rdExp = RdExpression(form, cond)
|
||||||
|
|
||||||
self.assertEqual(rdExp._letters, {'a'})
|
assert rdExp._letters == {'a'}
|
||||||
self.assertEqual(rdExp._2replaced, {'a'})
|
assert rdExp._2replaced == {'a'}
|
||||||
|
|
||||||
rdExp()
|
rdExp()
|
||||||
self.assertEqual(set(rdExp._gene_varia.keys()), {'a'})
|
assert set(rdExp._gene_varia.keys()) == {'a'}
|
||||||
self.assertEqual(set(rdExp._gene_2replaced.keys()), {'a'})
|
assert set(rdExp._gene_2replaced.keys()) == {'a'}
|
||||||
|
|
||||||
self.assertTrue(rdExp._gene_varia['a'] in list(range(5)))
|
assert rdExp._gene_varia['a'] in list(range(5))
|
||||||
self.assertTrue(rdExp._gene_varia['a'] % 2 == 1)
|
assert rdExp._gene_varia['a'] % 2 == 1
|
||||||
|
|
||||||
def test_only_form_calc_cond(self):
|
def test_only_form_calc_cond():
|
||||||
form = "{a*3} * {b}"
|
form = "{a*3} * {b}"
|
||||||
cond = ["{a} == 3"]
|
cond = ["{a} == 3"]
|
||||||
rdExp = RdExpression(form, cond)
|
rdExp = RdExpression(form, cond)
|
||||||
|
|
||||||
self.assertEqual(rdExp._letters, {'a', 'b'})
|
assert rdExp._letters, {'a' == 'b'}
|
||||||
self.assertEqual(rdExp._2replaced, {'a', 'b', 'a*3'})
|
assert rdExp._2replaced, {'a', 'b' == 'a*3'}
|
||||||
|
|
||||||
rdExp()
|
rdExp()
|
||||||
self.assertEqual(set(rdExp._gene_varia.keys()), {'a', 'b'})
|
assert set(rdExp._gene_varia.keys()), {'a' == 'b'}
|
||||||
self.assertEqual(set(rdExp._gene_2replaced.keys()), {'a', 'b', 'a*3'})
|
assert set(rdExp._gene_2replaced.keys()), {'a', 'b' == 'a*3'}
|
||||||
|
|
||||||
self.assertEqual(rdExp._gene_varia['a'], 3)
|
assert rdExp._gene_varia['a'] == 3
|
||||||
|
|
||||||
|
def test_only_form_calc_cond_calc():
|
||||||
def test_only_form_calc_cond_calc(self):
|
|
||||||
form = "{a*3} * {b}"
|
form = "{a*3} * {b}"
|
||||||
cond = ["{a+b} == 3"]
|
cond = ["{a+b} == 3"]
|
||||||
rdExp = RdExpression(form, cond)
|
rdExp = RdExpression(form, cond)
|
||||||
|
|
||||||
self.assertEqual(rdExp._letters, {'a', 'b'})
|
assert rdExp._letters, {'a' == 'b'}
|
||||||
self.assertEqual(rdExp._2replaced, {'b', 'a*3', 'a+b'})
|
assert rdExp._2replaced, {'b', 'a*3' == 'a+b'}
|
||||||
|
|
||||||
rdExp()
|
rdExp()
|
||||||
self.assertEqual(set(rdExp._gene_varia.keys()), {'a', 'b'})
|
assert set(rdExp._gene_varia.keys()), {'a' == 'b'}
|
||||||
self.assertEqual(set(rdExp._gene_2replaced.keys()), {'b', 'a*3', 'a+b'})
|
assert set(rdExp._gene_2replaced.keys()), {'b', 'a*3' == 'a+b'}
|
||||||
|
|
||||||
self.assertEqual((rdExp._gene_varia['a'] + rdExp._gene_varia['b']), 3)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
unittest.main()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
assert (rdExp._gene_varia['a'] + rdExp._gene_varia['b']) == 3
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user