def test_example_1(self): text = "a bb ccc" avg_word_length = P.Pipe( text, Obj.split(" "), #['a', 'bb', 'ccc'] P.map(len), #[1, 2, 3] P._(sum) / len #6 / 3 == 2 ) assert 2 == avg_word_length text = "a bb ccc" avg_word_length = P.Pipe( text, Obj.split(" "), #['a', 'bb', 'ccc'] P.map(len), #[1, 2, 3] M(sum) / len #6 / 3 == 2 ) assert 2 == avg_word_length text = "a bb ccc" avg_word_length = P.Pipe( text, Obj.split(" "), #['a', 'bb', 'ccc'] P.map(len), #[1, 2, 3] P.sum() / P.len() #6 / 3 == 2 ) assert 2 == avg_word_length avg_word_length = P.Pipe( "1 22 333", Obj.split(' '), # ['1', '22', '333'] P.map(len), # [1, 2, 3] [ sum # 1 + 2 + 3 == 6 , len # len([1, 2, 3]) == 3 ], P[0] / P[1] # sum / len == 6 / 3 == 2 ) assert avg_word_length == 2
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
def test_underscores(self): assert P._(a2_plus_b_minus_2c, 2, 4)(3) == 3 # (3)^2 + 2 - 2*4 assert P._2(a2_plus_b_minus_2c, 2, 4)(3) == -1 # (2)^2 + 3 - 2*4 assert P._3(a2_plus_b_minus_2c, 2, 4)(3) == 2 # (2)^2 + 4 - 2*3
def test_1(self): assert 9 == 2 >> P.Make( P + 1, P._(math.pow, 2) )