Back to index

radiance  4R0+20100331
test_histo.py
Go to the documentation of this file.
00001 
00002 import os
00003 import string
00004 import unittest
00005 
00006 from unit_tools import support
00007 from unit_tools import lcompare
00008 
00009 class HistoTestCase(unittest.TestCase):
00010        def setUp(self):
00011               self.oldpath = os.environ['PATH']
00012               os.environ['PATH'] = os.path.abspath(support.BINDIR)
00013 
00014        def tearDown(self):
00015               os.environ['PATH'] = self.oldpath
00016 
00017        def test_histo(self):
00018               cmd = 'histo -0.5 8.5 9 < "%s"' % support.datafile('histo.dat')
00019               raw = os.popen(cmd).read()
00020               result = map(string.split,string.split(raw,'\n'))
00021               expect = [
00022                      [0, 720, 240, 432, 1080, 270],
00023                      [1, 720, 240, 432, 1080, 270],
00024                      [2, 720, 240, 432,    0, 270],
00025                      [3,   0, 240, 432,    0, 270],
00026                      [4,   0, 240, 432,    0, 270],
00027                      [5,   0, 240,   0,    0, 270],
00028                      [6,   0, 240,   0,    0, 270],
00029                      [7,   0, 240,   0,    0, 270],
00030                      [8,   0, 240,   0,    0,   0],
00031               ]
00032               try: lcompare.llcompare(result, expect, ignore_empty=1)
00033               except lcompare.error, e:
00034                      self.fail('%s [%s]' % (str(e),cmd))
00035 
00036        def test_histo_c(self):
00037               cmd = 'histo -c -0.5 8.5 9 < "%s"' % support.datafile('histo.dat')
00038               raw = os.popen(cmd).read()
00039               result = map(string.split,string.split(raw,'\n'))
00040               expect = [
00041                      [-0.5,   0,    0,    0,    0,    0],
00042                      [0.5,  720,  240,  432, 1080,  270],
00043                      [1.5, 1440,  480,  864, 2160,  540],
00044                      [2.5, 2160,  720, 1296, 2160,  810],
00045                      [3.5, 2160,  960, 1728, 2160, 1080],
00046                      [4.5, 2160, 1200, 2160, 2160, 1350],
00047                      [5.5, 2160, 1440, 2160, 2160, 1620],
00048                      [6.5, 2160, 1680, 2160, 2160, 1890],
00049                      [7.5, 2160, 1920, 2160, 2160, 2160],
00050                      [8.5, 2160, 2160, 2160, 2160, 2160],
00051               ]
00052               try: lcompare.llcompare(result, expect, ignore_empty=1)
00053               except lcompare.error, e:
00054                      self.fail('%s [%s]' % (str(e),cmd))
00055 
00056        def test_histo_p(self):
00057               cmd = 'histo -p -0.5 8.5 9 < "%s"' % support.datafile('histo.dat')
00058               raw = os.popen(cmd).read()
00059               result = map(string.split,string.split(raw,'\n'))
00060               expect = [
00061                      [0, 33.333333, 11.111111, 20.0, 50.0, 12.5],
00062                      [1, 33.333333, 11.111111, 20.0, 50.0, 12.5],
00063                      [2, 33.333333, 11.111111, 20.0,  0.0, 12.5],
00064                      [3,       0.0, 11.111111, 20.0,  0.0, 12.5],
00065                      [4,       0.0, 11.111111, 20.0,  0.0, 12.5],
00066                      [5,       0.0, 11.111111,  0.0,  0.0, 12.5],
00067                      [6,       0.0, 11.111111,  0.0,  0.0, 12.5],
00068                      [7,       0.0, 11.111111,  0.0,  0.0, 12.5],
00069                      [8,       0.0, 11.111111,  0.0,  0.0,  0.0],
00070               ]
00071               try: lcompare.llcompare(result, expect, ignore_empty=1)
00072               except lcompare.error, e:
00073                      self.fail('%s [%s]' % (str(e),cmd))
00074 
00075        def test_histo_pc(self):
00076               cmd = 'histo -p -c -0.5 8.5 9 < "%s"' % support.datafile('histo.dat')
00077               raw = os.popen(cmd).read()
00078               result = map(string.split,string.split(raw,'\n'))
00079               expect = [
00080                      [-0.5,      0.0,       0.0,   0.0,   0.0,   0.0],
00081                      [0.5, 33.333333, 11.111111,  20.0,  50.0,  12.5],
00082                      [1.5, 66.666667, 22.222222,  40.0, 100.0,  25.0],
00083                      [2.5,     100.0, 33.333333,  60.0, 100.0,  37.5],
00084                      [3.5,     100.0, 44.444444,  80.0, 100.0,  50.0],
00085                      [4.5,     100.0, 55.555556, 100.0, 100.0,  62.5],
00086                      [5.5,     100.0, 66.666667, 100.0, 100.0,  75.0],
00087                      [6.5,     100.0, 77.777778, 100.0, 100.0,  87.5],
00088                      [7.5,     100.0, 88.888889, 100.0, 100.0, 100.0],
00089                      [8.5,     100.0,     100.0, 100.0, 100.0, 100.0],
00090               ]
00091               try: lcompare.llcompare(result, expect, ignore_empty=1)
00092               except lcompare.error, e:
00093                      self.fail('%s [%s]' % (str(e),cmd))
00094 
00095 def main():
00096        support.run_case(HistoTestCase)
00097 
00098 if __name__ == '__main__':
00099        main()
00100 
00101 # vi: set ts=4 sw=4 :