Example #1
0
    def test_lshift(self):

        f = P * 2 << P + 1

        assert 6 == f(2)

        f = lambda x: x * 3
        g = lambda x: x + 2

        h = g << P.Make(f)

        assert 11 == h(3)

        h = P.Make(g) << f

        assert 11 == h(3)
Example #2
0
    def test_compose(self):
        f = P.Make(
            P + 1,
            P * 2,
            P + 4
        )

        assert 10 == f(2)
Example #3
0
    def test_rrshift(self):
        builder = P.Make(
            P + 1,
            P * 2,
            P + 4
        )

        assert 10 == 2 >> builder
Example #4
0
    def test_rshift(self):

        f = P + 1 >> P * 2

        assert 6 == f(2)

        f = lambda x: x * 3
        g = lambda x: x + 2

        h = f >> P.Make(g)

        assert 11 == h(3)

        h = P.Make(f) >> g
        assert 11 == h(3)

        y = 1 >> P + 1 >> P * 2
        assert 4 == y

        y = P * 2 << P + 1 << 1
        assert 4 == y
Example #5
0
    def test_2(self):
        assert [2, 4] == [1, 2, 3] >> P.Make(
            P
            ._2(map, P + 1)
            ._2(filter, P % 2 == 0)
        )

        assert [2, 4] == P.Pipe(
            [1, 2, 3],
            P
            ._2(map, P + 1)
            ._2(filter, P % 2 == 0)
        )
Example #6
0
    def test_0(self):
        from datetime import datetime
        import time

        t0 = datetime.now()

        time.sleep(0.01)

        t1 = 2 >> P.Make(
            P + 1,
            P._0(datetime.now)
        )

        assert t1 > t0
Example #7
0
    def test_compose_list_reduce(self):
        f = P.Make(
            P + 1,
            P * 2,
            P + 4,
            [
                P + 2
            ,
                P / 2
            ],
            sum
        )

        assert 17 == f(2)
Example #8
0
    def test_compose_list(self):
        f = P.Make(
            P + 1,
            P * 2, {'x'},
            P + 4,
            [
                P + 2
            ,
                P / 2
            ,
                'x'
            ]
        )

        assert [12, 5, 6] == f(2)
Example #9
0
    def test_C_1(self):
        assert P._(add2)(4) == 6
        assert P._(add2)._(mul3)(4) == 18

        assert P.Make(add2)(4) == 6
        assert P.Make(add2, mul3)(4) == 18
Example #10
0
    def test_reference(self):
        add_ref = P.Ref('add_ref')

        assert 8 == 3 >> P.Make(P.add(2).On(add_ref).add(3))
        assert 5 == add_ref()
Example #11
0
 def test_1(self):
     assert 9 == 2 >> P.Make(
         P + 1,
         P._(math.pow, 2)
     )