Пример #1
0
def compose_test():
    composed = compose(
        sub2,
        double,
        add10
    )
    assert_equal(composed(100), 218)
Пример #2
0
def pipe_test():
    piped = pipe(
        sub2,
        double,
        add10
    )
    assert_equal(piped(100), (100-2)*2+10)
Пример #3
0
def tap_test():
    called_box = [False]

    def set_called(v):
        called_box[0] = True

    assert_equal(tap(set_called, 42), 42)
    assert called_box[0]
Пример #4
0
def identity_test():
    assert_equal(identity(3), 3)
Пример #5
0
def product_test():
    assert_equal(product([2, 3, 5]), 30)
Пример #6
0
def min_test():
    assert_equal(min([3, 1, 4, 2]), 1)
Пример #7
0
def subtract_nocurry_test():
    assert_equal(subtract(4, 3), 1)
Пример #8
0
def apply_nocurry_test():
    assert_equal(apply(add, [1, 2]), 3)
Пример #9
0
def greater_curry_test():
    min5 = greater(5)
    assert_equal(min5(3), 5)
    assert_equal(min5(7), 7)
Пример #10
0
def item_path_curry_test():
    get_abc = item_path(["a", "b", "c"])
    assert_equal(get_abc(test_dict), "foo")
Пример #11
0
def item_path_nocurry_test():
    assert_equal(item_path(["a", "b", "c"], test_dict), "foo")
Пример #12
0
def lesser_curry_test():
    max5 = lesser(5)
    assert_equal(max5(3), 3)
    assert_equal(max5(7), 5)
Пример #13
0
def lesser_nocurry_test():
    assert_equal(lesser(5, 3), 3)
    assert_equal(lesser(5, 7), 5)
Пример #14
0
def if_else_curry_test():
    inc_away_from_zero = if_else(positive, inc, dec)
    assert_equal(inc_away_from_zero(5), 6)
    assert_equal(inc_away_from_zero(-5), -6)
Пример #15
0
def if_else_nocurry_test():
    assert_equal(if_else(positive, inc, dec, 5), 6)
    assert_equal(if_else(positive, inc, dec, -5), -6)
Пример #16
0
def getitem_nocurry_item():
    assert_equal(getitem("a", {"a": 1}), 1)
Пример #17
0
def getattr_curry_test():
    assert_equal(getattr("val")(test_object), "foo")
Пример #18
0
def multiply_nocurry_test():
    assert_equal(multiply(3, 6), 18)
Пример #19
0
def divide_nocurry_test():
    assert_equal(divide(10, 5), 2)
Пример #20
0
def multiply_curry_test():
    assert_equal(multiply(3)(6), 18)
Пример #21
0
def apply_curry_test():
    assert_equal(apply(add)([1, 2]), 3)
Пример #22
0
def modulo_nocurry_test():
    assert_equal(modulo(12, 5), 2)
    assert_equal(modulo(-12, 5), 3)
Пример #23
0
def compose_test():
    composed = compose(sub2, double, add10)
    assert_equal(composed(100), 218)
Пример #24
0
def modulo_curry_test():
    assert_equal(modulo(12)(5), 2)
Пример #25
0
def subtract_curry_test():
    assert_equal(subtract(4)(3), 1)
Пример #26
0
def find_nocurry_test():
    assert_equal(find(positive, [-2, -1, 0, 1, 2]), 1)
Пример #27
0
def negate_test():
    assert_equal(negate(5), -5)
Пример #28
0
def add_nocurry_test():
    assert_equal(add(1, 2), 3)
Пример #29
0
def run_f_curry_cases(fc):
    assert_equal(fc(1, 1, 1), 3)
    assert_equal(fc(1, 1), 5)
    assert_equal(fc(1)(1), 5)
    assert_equal(fc(1)(1, 1), 3)
    assert_equal(fc(x=1, y=1, z=1), 3)
    assert_equal(fc(x=1, y=1), 5)
    assert_equal(fc(1)(y=1, z=1), 3)
    assert_equal(fc(1)(y=1), 5)
    assert_equal(fc(z=10)(1, 1), 12)
    assert_equal(fc(y=10)(1), 14)
Пример #30
0
def add_curry_test():
    assert_equal(add(1)(2), 3)
Пример #31
0
def mean_test():
    assert_equal(mean([3, 5, 7]), 5)
    assert_equal(mean([5, 7, 3]), 5)
Пример #32
0
def dec_test():
    assert_equal(dec(5), 4)
Пример #33
0
def getitem_curry_item():
    assert_equal(getitem("a")({"a": 1}))
Пример #34
0
def sum_test():
    assert_equal(sum([1, 2, 3]), 6)
Пример #35
0
def greater_nocurry_test():
    assert_equal(greater(5, 3), 5)
    assert_equal(greater(5, 7), 7)
Пример #36
0
def reduce_nocurry_test():
    assert_equal(reduce(string_append, "", ["aa", "bb", "cc"]), "aabbcc")
Пример #37
0
def inc_test():
    assert_equal(inc(5), 6)
Пример #38
0
def max_test():
    assert_equal(max([1, 3, 4, 2]), 4)
Пример #39
0
def divide_curry_test():
    assert_equal(divide(10)(5), 2)
Пример #40
0
def always_curry_test():
    always3 = always(3)
    assert_equal(always3("foo"), 3)