ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/test/testcases/cal/test_cnt.py
Revision: 1.1
Committed: Mon Mar 28 17:48:43 2016 UTC (9 years, 1 month ago) by schorsch
Content type: text/x-python
Branch: MAIN
CVS Tags: rad5R4, rad5R2, rad5R3, HEAD
Log Message:
Refactoring of test suite, use independently of SCons and with Py2.7 or 3.x.

File Contents

# User Rev Content
1 schorsch 1.1 # -*- coding: utf-8 -*-
2     from __future__ import division, print_function, unicode_literals
3    
4     import itertools
5     import unittest
6    
7     from pyradlib import lcompare
8     from pyradlib.pyrad_proc import PIPE, Error, ProcMixin
9    
10    
11     class CntTestCase(unittest.TestCase, ProcMixin):
12    
13     def _runit(self, cmd, actstr):
14     try:
15     proc = self.call_one(cmd, actstr, out=PIPE,
16     universal_newlines=True)
17     raw = proc.stdout.read()
18     except Error as e:
19     self.fail('%s [%s]' % (str(e), self.qjoin(cmd)))
20     finally:
21     proc.wait()
22     return [s.strip() for s in raw.split('\n') if s]
23    
24     def test_cnt_1d(self):
25     for n in (5,10,100,1000,5000, 10000, 99999):
26     cmd = ['cnt', str(n)]
27     exp = range(n)
28     raw = self._runit(cmd, 'test cnt 1dim')
29     res = [float(s) for s in raw if s]
30     try: lcompare.lcompare(res, exp)
31     except lcompare.error as e:
32     self.fail(('test_cnt_1 n=%d - ' % n) + str(e))
33    
34     def test_cnt_2d(self):
35     # values higher than 1000/1000 will take rather long
36     for n,m in ((3,3), (10,5), (100,200), ):#(1000,200)):
37     cmd = ['cnt', str(n), str(m)]
38     exp = itertools.product(range(n), range(m))
39     raw = self._runit(cmd, 'test cnt 2dim')
40     res = [[float(ss) for ss in s.split('\t')] for s in raw]
41     try: lcompare.llcompare(res, exp)
42     except lcompare.error as e:
43     self.fail(('test_cnt_2 %d/%d - ' % (n,m)) + str(e))
44    
45     def test_cnt_3d(self):
46     # values higher than 100/100/100 will take rather long
47     for n,m,o in ((3,3,3), (10,5,7), (44, 33,22),):# (200,50,10)):
48     cmd = ['cnt', str(n), str(m), str(o)]
49     exp = itertools.product(range(n), range(m), range(o))
50     res = self._runit(cmd, 'test cnt 3dim')
51     res = [[float(ss) for ss in s.split('\t')] for s in res]
52     try: lcompare.llcompare(res, exp)
53     except lcompare.error as e:
54     self.fail(('test_cnt_3 %d/%d/%d - ' % (n,m,o)) + str(e))
55    
56    
57     # vi: set ts=4 sw=4 :