From 1404c6fa356c57d61a7025c453f7ddb29f44c0c4 Mon Sep 17 00:00:00 2001 From: Benjamin Bertrand Date: Sun, 17 Jan 2016 18:03:04 +0300 Subject: [PATCH] Remove unittest module in test_random_expression --- .../calculus/test/test_random_expression.py | 129 ++++++++---------- 1 file changed, 57 insertions(+), 72 deletions(-) diff --git a/pymath/calculus/test/test_random_expression.py b/pymath/calculus/test/test_random_expression.py index 5c6daa6..9cbdb68 100644 --- a/pymath/calculus/test/test_random_expression.py +++ b/pymath/calculus/test/test_random_expression.py @@ -2,103 +2,88 @@ # encoding: utf-8 -import unittest from pymath.calculus.random_expression import RdExpression -class TestRandomExpression(unittest.TestCase): - """Testing functions from pymath.calculus.random_expression""" +def test_only_form(): + form = "{a} + 2" + rdExp = RdExpression(form) - def test_only_form(self): - form = "{a} + 2" - rdExp = RdExpression(form) + assert rdExp._letters == {'a'} + assert rdExp._2replaced == {'a'} - self.assertEqual(rdExp._letters, {'a'}) - self.assertEqual(rdExp._2replaced, {'a'}) + rdExp() + assert set(rdExp._gene_varia.keys()) == {'a'} + assert set(rdExp._gene_2replaced.keys()) == {'a'} - rdExp() - self.assertEqual(set(rdExp._gene_varia.keys()), {'a'}) - self.assertEqual(set(rdExp._gene_2replaced.keys()), {'a'}) +def test_only_form_calc(): + form = "{a+b} + 2" + rdExp = RdExpression(form) - def test_only_form_calc(self): - form = "{a+b} + 2" - rdExp = RdExpression(form) + assert rdExp._letters, {'a' == 'b'} + assert rdExp._2replaced == {'a+b'} - self.assertEqual(rdExp._letters, {'a', 'b'}) - self.assertEqual(rdExp._2replaced, {'a+b'}) + rdExp() + assert set(rdExp._gene_varia.keys()), {'a' == 'b'} + assert set(rdExp._gene_2replaced.keys()) == {'a+b'} - rdExp() - self.assertEqual(set(rdExp._gene_varia.keys()), {'a', 'b'}) - self.assertEqual(set(rdExp._gene_2replaced.keys()), {'a+b'}) +def test_only_form_cond(): + form = "{a} + 2" + cond = ["{a} == 3"] + rdExp = RdExpression(form, cond) - def test_only_form_cond(self): - form = "{a} + 2" - cond = ["{a} == 3"] - rdExp = RdExpression(form, cond) + assert rdExp._letters == {'a'} + assert rdExp._2replaced == {'a'} - self.assertEqual(rdExp._letters, {'a'}) - self.assertEqual(rdExp._2replaced, {'a'}) + rdExp() + assert set(rdExp._gene_varia.keys()) == {'a'} + assert set(rdExp._gene_2replaced.keys()) == {'a'} - rdExp() - self.assertEqual(set(rdExp._gene_varia.keys()), {'a'}) - self.assertEqual(set(rdExp._gene_2replaced.keys()), {'a'}) + assert rdExp._gene_varia['a'] == 3 - self.assertEqual(rdExp._gene_varia['a'], 3) +def test_only_form_conds(): + form = "{a} + 2" + cond = ["{a} in list(range(5))", "{a} % 2 == 1"] + rdExp = RdExpression(form, cond) - def test_only_form_conds(self): - form = "{a} + 2" - cond = ["{a} in list(range(5))", "{a} % 2 == 1"] - rdExp = RdExpression(form, cond) + assert rdExp._letters == {'a'} + assert rdExp._2replaced == {'a'} - self.assertEqual(rdExp._letters, {'a'}) - self.assertEqual(rdExp._2replaced, {'a'}) + rdExp() + assert set(rdExp._gene_varia.keys()) == {'a'} + assert set(rdExp._gene_2replaced.keys()) == {'a'} - rdExp() - self.assertEqual(set(rdExp._gene_varia.keys()), {'a'}) - self.assertEqual(set(rdExp._gene_2replaced.keys()), {'a'}) + assert rdExp._gene_varia['a'] in list(range(5)) + assert rdExp._gene_varia['a'] % 2 == 1 - self.assertTrue(rdExp._gene_varia['a'] in list(range(5))) - self.assertTrue(rdExp._gene_varia['a'] % 2 == 1) +def test_only_form_calc_cond(): + form = "{a*3} * {b}" + cond = ["{a} == 3"] + rdExp = RdExpression(form, cond) - def test_only_form_calc_cond(self): - form = "{a*3} * {b}" - cond = ["{a} == 3"] - rdExp = RdExpression(form, cond) + assert rdExp._letters, {'a' == 'b'} + assert rdExp._2replaced, {'a', 'b' == 'a*3'} - self.assertEqual(rdExp._letters, {'a', 'b'}) - self.assertEqual(rdExp._2replaced, {'a', 'b', 'a*3'}) - - rdExp() - self.assertEqual(set(rdExp._gene_varia.keys()), {'a', 'b'}) - self.assertEqual(set(rdExp._gene_2replaced.keys()), {'a', 'b', 'a*3'}) - - self.assertEqual(rdExp._gene_varia['a'], 3) - - - def test_only_form_calc_cond_calc(self): - form = "{a*3} * {b}" - cond = ["{a+b} == 3"] - rdExp = RdExpression(form, cond) - - self.assertEqual(rdExp._letters, {'a', 'b'}) - self.assertEqual(rdExp._2replaced, {'b', 'a*3', 'a+b'}) - - rdExp() - self.assertEqual(set(rdExp._gene_varia.keys()), {'a', 'b'}) - self.assertEqual(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() + rdExp() + assert set(rdExp._gene_varia.keys()), {'a' == 'b'} + assert set(rdExp._gene_2replaced.keys()), {'a', 'b' == 'a*3'} + assert rdExp._gene_varia['a'] == 3 +def test_only_form_calc_cond_calc(): + form = "{a*3} * {b}" + cond = ["{a+b} == 3"] + rdExp = RdExpression(form, cond) + assert rdExp._letters, {'a' == 'b'} + assert rdExp._2replaced, {'b', 'a*3' == 'a+b'} + rdExp() + assert set(rdExp._gene_varia.keys()), {'a' == 'b'} + assert set(rdExp._gene_2replaced.keys()), {'b', 'a*3' == 'a+b'} + assert (rdExp._gene_varia['a'] + rdExp._gene_varia['b']) == 3