def test_ev_singleres(self): for expr, expect in self.ltest: cmd = ['ev', expr] result = self._runit(cmd) try: lcompare.lcompare([result], expect) except lcompare.error as e: self.fail('%s [%s]' % (str(e),cmd))
def test_call_1_bin(self): exp = (2160, 8640, 4320, 1080, 7560) cntcmd = ['total', '-of'] tfn = ts.datafile('histo.dat') res = self._runit(cntcmd, 'run one process', _in=tfn, nl=False) resl = struct.unpack('f'*len(exp), res) try: lcompare.lcompare(resl, exp) except lcompare.error as e: self.fail(('call_one_text n=%d -- ' % n) +str(e))
def test_cnt_1d(self): for n in (5,10,100,1000,5000, 10000, 99999): cmd = ['cnt', str(n)] exp = range(n) raw = self._runit(cmd, 'test cnt 1dim') res = [float(s) for s in raw if s] try: lcompare.lcompare(res, exp) except lcompare.error as e: self.fail(('test_cnt_1 n=%d - ' % n) + str(e))
def test_call_1_text(self): for n in (5, 10, 55, 200,1328,1329,1330,1331,1332, 2000, 5000,99999): exp = range(n) cntcmd = ['cnt', str(n)] res = self._runit(cntcmd, 'run one process', nl=True) resl = [r[0] for r in res] try: lcompare.lcompare(resl, exp) except lcompare.error as e: print(resl, exp) self.fail(('call_one_text n=%d -- ' % n) +str(e))
def test_recno_oascii(self): for n in (5, 10, 55, 200,1321, 1328,1329,1330,1331,1332, 2000, 3721, 5000,9876): orig = range(n) exp = [i+1 for i in orig] cntcmd = ['cnt', str(n)] aacmd = ['rcalc', '-e', '$1=recno'] aresl = self._runit(cntcmd, aacmd, 'calculate recno', nl=True) try: lcompare.lcompare(aresl, exp) except lcompare.error as e: self.fail(('recno_oascii n=%d -- ' % n) +str(e))
def test_call_1_bin(self): exp = (2160, 8640, 4320, 1080, 7560) cntcmd = ['total', '-of'] tfn = ts.datafile('histo.dat') res = self._runit(cntcmd, 'run one process', _in=tfn, nl=False) resl = struct.unpack('f' * len(exp), res) try: lcompare.lcompare(resl, exp) except lcompare.error as e: self.fail(('call_one_text n=%d -- ' % n) + str(e))
def test_call_2_bin(self): for nn in ((1,1,1), (5,5,5), (3,9,5,2,8)): totalrows = reduce(operator.mul, nn) exp = [reduce(operator.add, range(n))*(totalrows/n) for n in nn] cntcmd = ['cnt'] + [str(n) for n in nn] totcmd = ['total', '-of'] res = self._runit([cntcmd, totcmd], ['run p1','run p2']) resl = struct.unpack('f'*len(exp), res) try: lcompare.lcompare(resl, exp) except lcompare.error as e: self.fail(('call_one_text n=%d -- ' % n) +str(e))
def test_call_2_text(self): # with values higher than 44721, total will return a float in e-format. for n in (5, 10, 55, 200,1328,1329,1330,1331,1332, 2000, 5000, 44721, 44722, 99999): exp = [reduce(operator.add, range(n))] cntcmd = ['cnt', str(n)] totcmd = ['total'] resl = self._runit([cntcmd, totcmd], ['run p1','run p2'], nl=True) try: lcompare.lcompare(resl, [exp]) except lcompare.error as e: self.fail(('call_one_text n=%d -- ' % n) +str(e))
def test_recno_oascii(self): for n in (5, 10, 55, 200, 1321, 1328, 1329, 1330, 1331, 1332, 2000, 3721, 5000, 9876): orig = range(n) exp = [i + 1 for i in orig] cntcmd = ['cnt', str(n)] aacmd = ['rcalc', '-e', '$1=recno'] aresl = self._runit(cntcmd, aacmd, 'calculate recno', nl=True) try: lcompare.lcompare(aresl, exp) except lcompare.error as e: self.fail(('recno_oascii n=%d -- ' % n) + str(e))
def test_call_2_text(self): # with values higher than 44721, total will return a float in e-format. for n in (5, 10, 55, 200, 1328, 1329, 1330, 1331, 1332, 2000, 5000, 44721, 44722, 99999): exp = [reduce(operator.add, range(n))] cntcmd = ['cnt', str(n)] totcmd = ['total'] resl = self._runit([cntcmd, totcmd], ['run p1', 'run p2'], nl=True) try: lcompare.lcompare(resl, [exp]) except lcompare.error as e: self.fail(('call_one_text n=%d -- ' % n) + str(e))
def test_call_1_text(self): for n in (5, 10, 55, 200, 1328, 1329, 1330, 1331, 1332, 2000, 5000, 99999): exp = range(n) cntcmd = ['cnt', str(n)] res = self._runit(cntcmd, 'run one process', nl=True) resl = [r[0] for r in res] try: lcompare.lcompare(resl, exp) except lcompare.error as e: print(resl, exp) self.fail(('call_one_text n=%d -- ' % n) + str(e))
def test_call_many_bin(self): exp = (15, 40, 45, 48, 0) cmd0 = ['cnt', '3', '4', '5', '1'] cmd1 = ['histo', '1', '5'] cmd2 = ['total', '-of'] cmdl = [cmd0, cmd1, cmd2] res = self._runit(cmdl, 'run many processes') resl = struct.unpack('f'*len(exp), res) try: lcompare.lcompare(resl, exp) except lcompare.error as e: print(resl, exp) self.fail(('call_one_text -- ') +str(e))
def test_call_many_bin(self): exp = (15, 40, 45, 48, 0) cmd0 = ['cnt', '3', '4', '5', '1'] cmd1 = ['histo', '1', '5'] cmd2 = ['total', '-of'] cmdl = [cmd0, cmd1, cmd2] res = self._runit(cmdl, 'run many processes') resl = struct.unpack('f' * len(exp), res) try: lcompare.lcompare(resl, exp) except lcompare.error as e: print(resl, exp) self.fail(('call_one_text -- ') + str(e))
def test_call_2_bin(self): for nn in ((1, 1, 1), (5, 5, 5), (3, 9, 5, 2, 8)): totalrows = reduce(operator.mul, nn) exp = [ reduce(operator.add, range(n)) * (totalrows / n) for n in nn ] cntcmd = ['cnt'] + [str(n) for n in nn] totcmd = ['total', '-of'] res = self._runit([cntcmd, totcmd], ['run p1', 'run p2']) resl = struct.unpack('f' * len(exp), res) try: lcompare.lcompare(resl, exp) except lcompare.error as e: self.fail(('call_one_text n=%d -- ' % n) + str(e))
def test_lc_split_radfile(self): df = ts.datafile('window_src.rad') exp = ([['#'], ['#', 'A', 'plain', 'old', 'glass', 'window'], ['#'], [], ['void', 'light', 'window_light'], [0], [0], [3, 1, 1, 1], [], ['window_light', 'polygon', 'window'], [0], [0], [12], [23.5, 43, 30], [23.5, 26, 30], [-23.5, 26, 30], [-23.5, 43, 30], []]) resl = lcompare.split_radfile(df) try: lcompare.lcompare(resl, exp) except lcompare.error as e: print(resl, exp) self.fail(('call_one_text n=%d -- ' % n) +str(e))
def test_recno_odouble(self): for n in (5, 10, 55, 200,1321, 1328,1329,1330,1331,1332, 2000, 3721, 5000): orig = range(n) exp = (i+1 for i in orig) cntcmd = ['cnt', str(n)] adcmd = ['rcalc', '-od', '-e', '$1=recno'] res = self._runit(cntcmd, adcmd, 'calculate recno') if len(res) != n * 8: self.fail(('recno_odouble n=%d -- Length of resulting data ' 'differs from expected (%d != %d)') % (n, len(res), n*8)) iresl = struct.unpack('d'*n, res) try: lcompare.lcompare(iresl, exp) except lcompare.error as e: self.fail(('recno_odouble n=%d -- ' % n) +str(e))
def test_recno_odouble(self): for n in (5, 10, 55, 200, 1321, 1328, 1329, 1330, 1331, 1332, 2000, 3721, 5000): orig = range(n) exp = (i + 1 for i in orig) cntcmd = ['cnt', str(n)] adcmd = ['rcalc', '-od', '-e', '$1=recno'] res = self._runit(cntcmd, adcmd, 'calculate recno') if len(res) != n * 8: self.fail(('recno_odouble n=%d -- Length of resulting data ' 'differs from expected (%d != %d)') % (n, len(res), n * 8)) iresl = struct.unpack('d' * n, res) try: lcompare.lcompare(iresl, exp) except lcompare.error as e: self.fail(('recno_odouble n=%d -- ' % n) + str(e))
def test_call_many_text(self): data = b'''void polygon test 0 0 9 0 0 0 1 0 0 0 1 0''' exp = (['#', 'xform', '-s', 0.5], ['#', 'xform', '-t', 0, 0, 2], ['#', 'xform', '-ry', -20], ['#', 'xform', '-rx', 30], ['void', 'polygon', 'test'], [0], [0], [9], [0, 0, 1], [0.469846310393, 0, 1.17101007167], [-0.0855050358315, 0.433012701892, 1.23492315519]) cmd0 = ['xform', '-rx', '30'] cmd1 = ['xform', '-ry', '-20'] cmd2 = ['xform', '-t', '0', '0', '2'] cmd3 = ['xform', '-s', '0.5'] cmdl = [cmd0, cmd1, cmd2, cmd3] resl = self._runit(cmdl, 'run many processes', indata=data, _in=PIPE, nl=True) try: lcompare.lcompare(resl, exp) except lcompare.error as e: print(resl, exp) self.fail(('call_one_text n=%d -- ' % n) +str(e))
def test_call_many_text(self): data = b'''void polygon test 0 0 9 0 0 0 1 0 0 0 1 0''' exp = (['#', 'xform', '-s', 0.5], ['#', 'xform', '-t', 0, 0, 2], ['#', 'xform', '-ry', -20], ['#', 'xform', '-rx', 30], ['void', 'polygon', 'test'], [0], [0], [9], [0, 0, 1], [0.469846310393, 0, 1.17101007167], [-0.0855050358315, 0.433012701892, 1.23492315519]) cmd0 = ['xform', '-rx', '30'] cmd1 = ['xform', '-ry', '-20'] cmd2 = ['xform', '-t', '0', '0', '2'] cmd3 = ['xform', '-s', '0.5'] cmdl = [cmd0, cmd1, cmd2, cmd3] resl = self._runit(cmdl, 'run many processes', indata=data, _in=PIPE, nl=True) try: lcompare.lcompare(resl, exp) except lcompare.error as e: print(resl, exp) self.fail(('call_one_text n=%d -- ' % n) + str(e))