11import unittest
22
33from shunting_yard import tokenize
4- from shunting_yard .tokenize import _remove_implicit_multiplication
4+ from shunting_yard .tokenize import _convert_scientific_notation , _remove_implicit_multiplication
55
66
77class TestTokenizer (unittest .TestCase ):
@@ -106,6 +106,7 @@ def test_digit_other(self):
106106 self .assertEqual (_remove_implicit_multiplication ('3cos(5)' ), '3*cos(5)' )
107107 self .assertEqual (_remove_implicit_multiplication ('3_func(0)' ), '3*_func(0)' )
108108 self .assertEqual (_remove_implicit_multiplication ('1(2+3)' ), '1*(2+3)' )
109+ self .assertEqual (_remove_implicit_multiplication ('1(2(3(4(5(6(7(8(9(10+0)))))))))' ), '1*(2*(3*(4*(5*(6*(7*(8*(9*(10+0)))))))))' )
109110
110111 def test_implicit_mult_double_brackets (self ):
111112 self .assertEqual (_remove_implicit_multiplication ('(1+2)(3+4)' ), '(1+2)*(3+4)' )
@@ -127,6 +128,30 @@ def test_with_longer_numbers(self):
127128 self .assertEqual (_remove_implicit_multiplication ('1+200x' ), '1+200*x' )
128129
129130
131+ class TestScientificNotation (unittest .TestCase ):
132+
133+ def test_not_present (self ):
134+ self .assertEqual (_convert_scientific_notation ('abc' ), 'abc' )
135+ self .assertEqual (_convert_scientific_notation ('123.4' ), '123.4' )
136+ self .assertEqual (_convert_scientific_notation ('123exp(4)' ), '123exp(4)' )
137+ self .assertEqual (_convert_scientific_notation ('123e +1' ), '123e +1' )
138+
139+ def test_present (self ):
140+ self .assertEqual (_convert_scientific_notation ('12e3' ), '12*10^(3)' )
141+ self .assertEqual (_convert_scientific_notation ('+12e3' ), '+12*10^(3)' )
142+ self .assertEqual (_convert_scientific_notation ('-12e3' ), '-12*10^(3)' )
143+ self .assertEqual (_convert_scientific_notation ('1.2e3' ), '1.2*10^(3)' )
144+ self .assertEqual (_convert_scientific_notation ('1.e3' ), '1.*10^(3)' )
145+ self .assertEqual (_convert_scientific_notation ('.2e3' ), '.2*10^(3)' )
146+ self .assertEqual (_convert_scientific_notation ('12e-3' ), '12*10^(-3)' )
147+ self .assertEqual (_convert_scientific_notation ('12e+3' ), '12*10^(+3)' )
148+ self .assertEqual (_convert_scientific_notation ('12e34' ), '12*10^(34)' )
149+ self .assertEqual (_convert_scientific_notation ('12e-34' ), '12*10^(-34)' )
150+ self .assertEqual (_convert_scientific_notation ('12e+34' ), '12*10^(+34)' )
151+
152+ def test_double (self ):
153+ self .assertEqual (_convert_scientific_notation ('12e3+45e-6' ), '12*10^(3)+45*10^(-6)' )
154+
130155
131156if __name__ == '__main__' :
132157 unittest .main ()
0 commit comments