| 1 |
# -*- coding: utf-8 -*- |
| 2 |
from __future__ import division, print_function, unicode_literals |
| 3 |
|
| 4 |
import math |
| 5 |
import unittest |
| 6 |
|
| 7 |
from pyradlib import lcompare |
| 8 |
from pyradlib.pyrad_proc import PIPE, Error, ProcMixin |
| 9 |
|
| 10 |
|
| 11 |
class EvTestCase(unittest.TestCase, ProcMixin): |
| 12 |
|
| 13 |
ltest = [ |
| 14 |
['2.3 + 5 * 21.7 / 1.43', [2.3 + 5 * 21.7 / 1.43]], |
| 15 |
['if(1, 1, 0)', [1]], |
| 16 |
['if(0, 1, 0)', [0]], |
| 17 |
['select(3, 1, 2, 3, 4, 5)', [3]], |
| 18 |
['floor(5.743)', [5]], |
| 19 |
['ceil(5.743)', [6]], |
| 20 |
['sqrt(7.4)', [math.sqrt(7.4)]], |
| 21 |
['exp(3.4)', [math.exp(3.4)]], |
| 22 |
['log(2.4)', [math.log(2.4)]], |
| 23 |
['log10(5.4)', [math.log10(5.4)]], |
| 24 |
['sin(.51)', [math.sin(.51)]], |
| 25 |
['cos(.41)', [math.cos(.41)]], |
| 26 |
['tan(0.77)', [math.tan(0.77)]], |
| 27 |
['asin(0.83)', [math.asin(0.83)]], |
| 28 |
['acos(.94)', [math.acos(.94)]], |
| 29 |
['atan(0.22)', [math.atan(0.22)]], |
| 30 |
['atan2(0.72, 0.54)', [math.atan2(0.72, 0.54)]], |
| 31 |
] |
| 32 |
|
| 33 |
def _runit(self, cmd): |
| 34 |
try: |
| 35 |
proc = self.call_one(cmd, 'call ev', out=PIPE, |
| 36 |
universal_newlines=True) |
| 37 |
raw = proc.stdout.read() |
| 38 |
except Error as e: |
| 39 |
self.fail('%s [%s]' % (str(e), self.qjoin(cmd))) |
| 40 |
finally: |
| 41 |
proc.wait() |
| 42 |
return raw.strip() |
| 43 |
|
| 44 |
def test_ev_singleres(self): |
| 45 |
for expr, expect in self.ltest: |
| 46 |
cmd = ['ev', expr] |
| 47 |
result = self._runit(cmd) |
| 48 |
try: lcompare.lcompare([result], expect) |
| 49 |
except lcompare.error as e: |
| 50 |
self.fail('%s [%s]' % (str(e),cmd)) |
| 51 |
|
| 52 |
def x_test_ev_multipleres(self): |
| 53 |
pass # XXX implement |
| 54 |
|
| 55 |
|
| 56 |
# vi: set ts=4 sw=4 : |