123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- #!/usr/bin/python3
- # copyright 2023 weber yann
- #
- # this file is part of rpnifs.
- #
- # geneifs is free software: you can redistribute it and/or modify
- # it under the terms of the gnu general public license as published by
- # the free software foundation, either version 3 of the license, or
- # (at your option) any later version.
- #
- # geneifs is distributed in the hope that it will be useful,
- # but without any warranty; without even the implied warranty of
- # merchantability or fitness for a particular purpose. see the
- # gnu general public license for more details.
- #
- # you should have received a copy of the gnu general public license
- # along with geneifs. if not, see <http://www.gnu.org/licenses/>.
- #
-
- import copy
- import pickle
- import random
- import sys
-
- import unittest
-
- try:
- import pyrpn
- except (ImportError, NameError) as e:
- print("error importing pyrpn. try to run make.",
- file=sys.stderr)
- raise e
-
-
- class TestRpnIterSequence(unittest.TestCase):
- """ Testing RPNIterExpr sequence methods """
-
- def test_len(self):
- """ Testing RPNIterExpr.__len__ with various values/constants """
- tests = [([pyrpn.const.POS_XY, pyrpn.const.RESULT_RGB, (1024,1024)],
- 5),
- ([pyrpn.const.POS_LINEAR, pyrpn.const.RESULT_CONST_RGBA, (1024,), (255,0,0,255)],
- 1),
- ([pyrpn.const.POS_XY, pyrpn.const.RESULT_CONST_RGBA, (640,480), (255,0,0,255)],
- 2),
- ([pyrpn.const.POS_LINEAR, pyrpn.const.RESULT_RGBA, (1024,)],
- 5),
- ([pyrpn.const.POS_XDIM, pyrpn.const.RESULT_RGB, (4, 2, 2, 640, 480)],
- 7),
- ]
- for args, expt_len in tests:
- rif=pyrpn.RPNIterExpr(*args)
- with self.subTest(rif=rif, expt_len=expt_len, args=args):
- self.assertEqual(expt_len, len(rif))
-
-
-
- class TestRPNIterMapping(unittest.TestCase):
- """ Testing RPNIterExpr mapping methods """
-
-
- def test_keys(self):
- """ Testing RPNIterExpr.__getitem__ with various values/constants """
- tests = [([pyrpn.const.POS_XY, pyrpn.const.RESULT_RGB, (1024,1024)],
- ['X', 'Y', 'R', 'G', 'B']),
- ([pyrpn.const.POS_LINEAR, pyrpn.const.RESULT_CONST_RGBA, (1024,), (255,0,0,255)],
- ['X']),
- ([pyrpn.const.POS_XY, pyrpn.const.RESULT_CONST_RGBA, (640,480), (255,0,0,255)],
- ['X', 'Y']),
- ([pyrpn.const.POS_LINEAR, pyrpn.const.RESULT_RGBA, (1024,)],
- ['X', 'R', 'G', 'B', 'A']),
- ([pyrpn.const.POS_XDIM, pyrpn.const.RESULT_RGB, (4, 2, 2, 640, 480)],
- ['D0', 'D1', 'D2', 'D3', 'R', 'G', 'B']),
- ]
- for args, keys in tests:
- rif=pyrpn.RPNIterExpr(*args)
- for curkey in keys:
- with self.subTest(rif=rif, key=curkey):
- expr = rif[curkey]
- expt = set(keys)
- self.assertEqual(set(rif.keys()), expt)
- for key, value in rif.items():
- with self.subTest(item=(key, value), id1=id(rif[key]),
- id2=id(value), rif=rif):
- self.assertEqual(rif[key], value)
-
- def test_assignement(self):
- """ Testing RPNIterExpr.__setitem__ """
- rif = pyrpn.RPNIterExpr(pyrpn.const.POS_XY, pyrpn.const.RESULT_RGB, (1024,1024))
- rif['X'] = 'A0 A1 +'
- for _ in range(1000):
- a, b = [random.randint(0,0xFFFF) for _ in range(2)]
- args = (a,b, 0,0,0)
- self.assertEqual(a+b, rif['X'].eval(*args))
- self.assertEqual(0, rif['Y'].eval(*args))
-
-
- if __name__ == '__main__':
- unittest.main()
|