Back to index

radiance  4R0+20100331
test_ev.py
Go to the documentation of this file.
00001 
00002 import os
00003 import math
00004 import string
00005 import unittest
00006 
00007 from unit_tools import support
00008 from unit_tools import lcompare
00009 
00010 class EvTestCase(unittest.TestCase):
00011        def setUp(self):
00012               self.oldpath = os.environ['PATH']
00013               os.environ['PATH'] = os.path.abspath(support.BINDIR)
00014 
00015        def tearDown(self):
00016               os.environ['PATH'] = self.oldpath
00017 
00018        ltest = [
00019               ['2.3 + 5 * 21.7 / 1.43', [2.3 + 5 * 21.7 / 1.43]],
00020               ['if(1, 1, 0)', [1]],
00021               ['if(0, 1, 0)', [0]],
00022               ['select(3, 1, 2, 3, 4, 5)', [3]],
00023               ['floor(5.743)', [5]],
00024               ['ceil(5.743)', [6]],
00025               ['sqrt(7.4)', [math.sqrt(7.4)]],
00026               ['exp(3.4)', [math.exp(3.4)]],
00027               ['log(2.4)', [math.log(2.4)]],
00028               ['log10(5.4)', [math.log10(5.4)]],
00029               ['sin(.51)', [math.sin(.51)]],
00030               ['cos(.41)', [math.cos(.41)]],
00031               ['tan(0.77)', [math.tan(0.77)]],
00032               ['asin(0.83)', [math.asin(0.83)]],
00033               ['acos(.94)', [math.acos(.94)]],
00034               ['atan(0.22)', [math.atan(0.22)]],
00035               ['atan2(0.72, 0.54)', [math.atan2(0.72, 0.54)]],
00036        ]
00037 
00038        def test_singleres(self):
00039               for expr, expect in self.ltest:
00040                      cmd = 'ev "%s"' % expr
00041                      result = [string.strip(os.popen(cmd).read())]
00042                      try: lcompare.lcompare(result, expect)
00043                      except lcompare.error, e:
00044                             self.fail('%s [%s]' % (str(e),cmd))
00045 
00046        def test_multipleres(self):
00047               pass # XXX implement
00048 
00049 def main():
00050        support.run_case(EvTestCase)
00051 
00052 if __name__ == '__main__':
00053        main()
00054 
00055 # vi: set ts=4 sw=4 :