ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/test/testcases/cal/test_histo.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
Log Message:
Refactoring of test suite, use independently of SCons and with Py2.7 or 3.x.

File Contents

# Content
1 # -*- coding: utf-8 -*-
2 from __future__ import division, print_function, unicode_literals
3
4 import unittest
5
6 import testsupport as ts
7 from pyradlib import lcompare
8 from pyradlib.pyrad_proc import PIPE, Error, ProcMixin
9
10
11 class HistoTestCase(unittest.TestCase, ProcMixin):
12
13 def _runit(self, cmd, fn):
14 try:
15 proc = self.call_one(cmd, 'call histo', _in=fn, 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 lcompare.split_rad(raw)
23
24 def test_histo(self):
25 infile = ts.datafile('histo.dat')
26 cmd = 'histo -0.5 8.5 9'.split()
27 result = self._runit(cmd, infile)
28 expect = [
29 [0, 720, 240, 432, 1080, 270],
30 [1, 720, 240, 432, 1080, 270],
31 [2, 720, 240, 432, 0, 270],
32 [3, 0, 240, 432, 0, 270],
33 [4, 0, 240, 432, 0, 270],
34 [5, 0, 240, 0, 0, 270],
35 [6, 0, 240, 0, 0, 270],
36 [7, 0, 240, 0, 0, 270],
37 [8, 0, 240, 0, 0, 0],
38 ]
39 try: lcompare.llcompare(result, expect, ignore_empty=1)
40 except lcompare.error as e:
41 self.fail('%s [%s]' % (str(e),cmd))
42
43 def test_histo_c(self):
44 infile = ts.datafile('histo.dat')
45 cmd = 'histo -c -0.5 8.5 9'.split()
46 result = self._runit(cmd, infile)
47 expect = [
48 [-0.5, 0, 0, 0, 0, 0],
49 [0.5, 720, 240, 432, 1080, 270],
50 [1.5, 1440, 480, 864, 2160, 540],
51 [2.5, 2160, 720, 1296, 2160, 810],
52 [3.5, 2160, 960, 1728, 2160, 1080],
53 [4.5, 2160, 1200, 2160, 2160, 1350],
54 [5.5, 2160, 1440, 2160, 2160, 1620],
55 [6.5, 2160, 1680, 2160, 2160, 1890],
56 [7.5, 2160, 1920, 2160, 2160, 2160],
57 [8.5, 2160, 2160, 2160, 2160, 2160],
58 ]
59 try: lcompare.llcompare(result, expect, ignore_empty=1)
60 except lcompare.error as e:
61 self.fail('%s [%s]' % (str(e),cmd))
62
63 def test_histo_p(self):
64 infile = ts.datafile('histo.dat')
65 cmd = 'histo -p -0.5 8.5 9'.split()
66 result = self._runit(cmd, infile)
67 expect = [
68 [0, 33.333333, 11.111111, 20.0, 50.0, 12.5],
69 [1, 33.333333, 11.111111, 20.0, 50.0, 12.5],
70 [2, 33.333333, 11.111111, 20.0, 0.0, 12.5],
71 [3, 0.0, 11.111111, 20.0, 0.0, 12.5],
72 [4, 0.0, 11.111111, 20.0, 0.0, 12.5],
73 [5, 0.0, 11.111111, 0.0, 0.0, 12.5],
74 [6, 0.0, 11.111111, 0.0, 0.0, 12.5],
75 [7, 0.0, 11.111111, 0.0, 0.0, 12.5],
76 [8, 0.0, 11.111111, 0.0, 0.0, 0.0],
77 ]
78 try: lcompare.llcompare(result, expect, ignore_empty=1)
79 except lcompare.error as e:
80 self.fail('%s [%s]' % (str(e),cmd))
81
82 def test_histo_pc(self):
83 infile = ts.datafile('histo.dat')
84 cmd = 'histo -p -c -0.5 8.5 9'.split()
85 result = self._runit(cmd, infile)
86 expect = [
87 [-0.5, 0.0, 0.0, 0.0, 0.0, 0.0],
88 [0.5, 33.333333, 11.111111, 20.0, 50.0, 12.5],
89 [1.5, 66.666667, 22.222222, 40.0, 100.0, 25.0],
90 [2.5, 100.0, 33.333333, 60.0, 100.0, 37.5],
91 [3.5, 100.0, 44.444444, 80.0, 100.0, 50.0],
92 [4.5, 100.0, 55.555556, 100.0, 100.0, 62.5],
93 [5.5, 100.0, 66.666667, 100.0, 100.0, 75.0],
94 [6.5, 100.0, 77.777778, 100.0, 100.0, 87.5],
95 [7.5, 100.0, 88.888889, 100.0, 100.0, 100.0],
96 [8.5, 100.0, 100.0, 100.0, 100.0, 100.0],
97 ]
98 try: lcompare.llcompare(result, expect, ignore_empty=1)
99 except lcompare.error as e:
100 self.fail('%s [%s]' % (str(e),cmd))
101
102
103 # vi: set ts=4 sw=4 :