| 1 |
schorsch |
1.1 |
|
| 2 |
|
|
import os |
| 3 |
|
|
import math |
| 4 |
|
|
import string |
| 5 |
|
|
import unittest |
| 6 |
|
|
|
| 7 |
|
|
from unit_tools import support |
| 8 |
|
|
from unit_tools import lcompare |
| 9 |
|
|
|
| 10 |
|
|
class EvTestCase(unittest.TestCase): |
| 11 |
|
|
def setUp(self): |
| 12 |
|
|
self.oldpath = os.environ['PATH'] |
| 13 |
|
|
os.environ['PATH'] = os.path.abspath(support.BINDIR) |
| 14 |
|
|
|
| 15 |
|
|
def tearDown(self): |
| 16 |
|
|
os.environ['PATH'] = self.oldpath |
| 17 |
|
|
|
| 18 |
|
|
ltest = [ |
| 19 |
|
|
['2.3 + 5 * 21.7 / 1.43', [2.3 + 5 * 21.7 / 1.43]], |
| 20 |
|
|
['if(1, 1, 0)', [1]], |
| 21 |
|
|
['if(0, 1, 0)', [0]], |
| 22 |
|
|
['select(3, 1, 2, 3, 4, 5)', [3]], |
| 23 |
|
|
['floor(5.743)', [5]], |
| 24 |
|
|
['ceil(5.743)', [6]], |
| 25 |
|
|
['sqrt(7.4)', [math.sqrt(7.4)]], |
| 26 |
|
|
['exp(3.4)', [math.exp(3.4)]], |
| 27 |
|
|
['log(2.4)', [math.log(2.4)]], |
| 28 |
|
|
['log10(5.4)', [math.log10(5.4)]], |
| 29 |
|
|
['sin(.51)', [math.sin(.51)]], |
| 30 |
|
|
['cos(.41)', [math.cos(.41)]], |
| 31 |
|
|
['tan(0.77)', [math.tan(0.77)]], |
| 32 |
|
|
['asin(0.83)', [math.asin(0.83)]], |
| 33 |
|
|
['acos(.94)', [math.acos(.94)]], |
| 34 |
|
|
['atan(0.22)', [math.atan(0.22)]], |
| 35 |
|
|
['atan2(0.72, 0.54)', [math.atan2(0.72, 0.54)]], |
| 36 |
|
|
] |
| 37 |
|
|
|
| 38 |
|
|
def test_singleres(self): |
| 39 |
|
|
for expr, expect in self.ltest: |
| 40 |
|
|
cmd = 'ev "%s"' % expr |
| 41 |
|
|
result = [string.strip(os.popen(cmd).read())] |
| 42 |
|
|
try: lcompare.lcompare(result, expect) |
| 43 |
|
|
except lcompare.error, e: |
| 44 |
|
|
self.fail('%s [%s]' % (str(e),cmd)) |
| 45 |
|
|
|
| 46 |
|
|
def test_multipleres(self): |
| 47 |
|
|
pass # XXX implement |
| 48 |
|
|
|
| 49 |
|
|
def main(): |
| 50 |
|
|
support.run_case(EvTestCase) |
| 51 |
|
|
|
| 52 |
|
|
if __name__ == '__main__': |
| 53 |
|
|
main() |
| 54 |
|
|
|
| 55 |
|
|
# vi: set ts=4 sw=4 : |