import unittest
import operator
import sandbox.chainop as chainop


class BasicChainTest (unittest.TestCase):
    def testBasicChain(self):
        double = lambda x: x * 2
        self.assertEqual(62, chainop.basic_chain((operator.add, double), 2, 31))
        square = lambda x: x ** 2
        self.assertEqual(2**31, chainop.basic_chain((operator.mul, square), 2, 31))


class MultiChainTest (unittest.TestCase):
    def testMultiChain(self):
        double = lambda x: x * 2
        self.assertEqual([62, 93], chainop.multi_chains((operator.add, double), (2, 3), 31))
        square = lambda x: x ** 2
        self.assertEqual([2**31, 3**31], chainop.multi_chains((operator.mul, square), [2, 3], 31))


def suite(suffix="Test"):
    suite = unittest.TestSuite()
    all_names = globals()
    for name in all_names:
        if name.endswith(suffix):
            suite.addTest(unittest.makeSuite(all_names[name], "test"))
    return suite

if __name__ == '__main__':
    runner = unittest.TextTestRunner()
    runner.run(suite())

[((23, 12, 23, 32), 'unittest.TestSuite', 'unittest.TestSuite', ({}, {}), '()', False, 'import unittest\n'), ((31, 13, 31, 38), 'unittest.TextTestRunner', 'unittest.TextTestRunner', ({}, {}), '()', False, 'import unittest\n'), ((9, 29, 9, 79), 'sandbox.chainop.basic_chain', 'chainop.basic_chain', ({(9, 49, 9, 71): '(operator.add, double)', (9, 73, 9, 74): '(2)', (9, 76, 9, 78): '(31)'}, {}), '((operator.add, double), 2, 31)', True, 'import sandbox.chainop as chainop\n'), ((11, 32, 11, 82), 'sandbox.chainop.basic_chain', 'chainop.basic_chain', ({(11, 52, 11, 74): '(operator.mul, square)', (11, 76, 11, 77): '(2)', (11, 79, 11, 81): '(31)'}, {}), '((operator.mul, square), 2, 31)', True, 'import sandbox.chainop as chainop\n'), ((17, 35, 17, 91), 'sandbox.chainop.multi_chains', 'chainop.multi_chains', ({(17, 56, 17, 78): '(operator.add, double)', (17, 80, 17, 86): '(2, 3)', (17, 88, 17, 90): '(31)'}, {}), '((operator.add, double), (2, 3), 31)', True, 'import sandbox.chainop as chainop\n'), ((19, 41, 19, 97), 'sandbox.chainop.multi_chains', 'chainop.multi_chains', ({(19, 62, 19, 84): '(operator.mul, square)', (19, 86, 19, 92): '[2, 3]', (19, 94, 19, 96): '(31)'}, {}), '((operator.mul, square), [2, 3], 31)', True, 'import sandbox.chainop as chainop\n'), ((27, 26, 27, 69), 'unittest.makeSuite', 'unittest.makeSuite', ({(27, 45, 27, 60): 'all_names[name]', (27, 62, 27, 68): '"""test"""'}, {}), "(all_names[name], 'test')", False, 'import unittest\n')]