Source

foonc / foonctest / foonctest.py

import unittest

from foonc import foonc

def inc(x):
    return x + 1

class FooncTests(unittest.TestCase):
    def setUp(self):
        super(FooncTests, self).setUp()

    def test_const(self):
        self.assertEqual(42, foonc.const(42)('whatever', is_passed='in'))

    def test_compose2(self):
        f = foonc._compose2(inc, int)
        self.assertEqual(42, f('41'))

    def test_compose_args(self):
        f = foonc.compose(str, inc, int)
        self.assertEqual('42', f('41'))

    def test_compose_list(self):
        f = foonc.compose([str, inc, int])
        self.assertEqual('42', f('41'))

    def test_flip(self):
        def f(*args):
            return args
        flipped = foonc.flip(f)
        self.assertEqual((3, 2, 1), flipped(1, 2, 3))


class FooncWrapperTests(unittest.TestCase):
    def setUp(self):
        super(FooncWrapperTests, self).setUp()

    def test_left_shift(self):
        f = foonc.wrap(int) >> inc
        self.assertEqual(42, f('41'))


def suite():
    suite = unittest.TestSuite()
    suite.addTests(unittest.makeSuite(FooncTests))
    suite.addTests(unittest.makeSuite(FooncWrapperTests))
    return suite


if __name__ == '__main__':
    unittest.main()