def pipe_test(): piped = pipe( sub2, double, add10 ) assert_equal(piped(100), (100-2)*2+10)
def compose_test(): composed = compose( sub2, double, add10 ) assert_equal(composed(100), 218)
def test_tap(): called_box = [False] def set_called(v): called_box[0] = True assert_equal(tap(set_called, 42), 42) assert called_box[0]
def clone_test(): a = {"a": 1} b = clone(a) assert_dicts_equal(a, b) b["a"] = 2 assert_equal(list(a.values()), [1]) assert_equal(list(b.values()), [2])
def test_assoc_path_nocurry(): assert_equal(assoc_path(["a", "b", "c"], 42, {"a": { "b": { "c": 0 } }}), {"a": { "b": { "c": 42 } }}) assert_equal(assoc_path(["a", "b", "c"], 42, {"a": 5}), {"a": { "b": { "c": 42 } }})
def filter_test(): assert_equal(filter(positive, [2, -1, 0, 3, -2]), [2, 3]) assert_equal(filter(positive)([2, -1, 0, 3, -2]), [2, 3]) assert_equal(filter(positive)(123), []) assert_equal(filter(is_even, { "a": 1, "b": 2, "c": 3, "d": 4 }), { "b": 2, "d": 4 })
def assoc_path_curry_test(): assert_equal( assoc_path(["a", "b", "c"])(42)({ "a": 5 }), {"a": { "b": { "c": 42 } }}) assert_equal( assoc_path(["a", "b", "c"], 42)({ "a": 5 }), {"a": { "b": { "c": 42 } }}) assert_equal( assoc_path(["a", "b", "c"])(42, { "a": 5 }), {"a": { "b": { "c": 42 } }})
def mean_test(): assert_equal(mean([3, 5, 7]), 5) assert_equal(mean([5, 7, 3]), 5)
def replace_curry_test(): assert_equal(replace('a', 'b')('aa'), 'bb')
def replace_curry_regex_test(): assert_equal(replace(r'a+', 'b')('aa'), 'b')
def group_by_no_curry_test(): assert_equal(group_by(grade, students), students_by_grade)
def test_apply_curry(): assert_equal(apply_to(42)(identity), 42) assert_equal(apply_to(42)(add(1)), 43)
def test_path_nocurry(): assert_equal(path(["a", "b", "c"], test_dict), "foo")
def find_nocurry_test(): assert_equal(find(positive, [-2, -1, 0, 1, 2]), 1)
def match_curry_regex_test(): assert_equal(match(r"a+")("aa"), ["aa"])
def test_subtract_curry(): assert_equal(subtract(4)(3), 1)
def test_subtract_nocurry(): assert_equal(subtract(4, 3), 1)
def test_juxt_nocurry(): assert_equal(juxt([add, sub])(1, 2), [3, -1])
def test_identity(): assert_equal(identity(3), 3)
def find_last_nocurry_test(): assert_equal(find_last(positive, [-2, -1, 0, 1, 2, -2]), 2)
def match_curry_test(): assert_equal(match("a")("aa"), ["a", "a"])
def test_path_throws(): try: path([], test_dict) except ValueError: assert_equal(True, True)
def not_found_test(): try: find(positive, []) except ValueError: assert_equal(True, True)
def item_path_curry_test(): get_abc = item_path(["a", "b", "c"]) assert_equal(get_abc(test_dict), "foo")
def not_found_test(): assert_equal(find_last(positive, []), None)
def item_path_throws_test(): try: item_path([], test_dict) except ValueError: assert_equal(True, True)
def sum_test(): assert_equal(sum([1, 2, 3]), 6)
def item_path_nocurry_test(): assert_equal(item_path(["a", "b", "c"], test_dict), "foo")
def test_apply_nocurry(): assert_equal(apply_to(42, identity), 42) assert_equal(apply_to(42, add(1)), 43)
def n_ary_curry_test(): assert_equal(n_args(takes_one_arg), 1) assert_equal(n_args(takes_three_args), 3) assert_equal(n_args(takes_two_args), 2) assert_equal(takes_one_arg(1), [1, None]) try: takes_one_arg(1, 2, 3) assert False, "takes_one_arg(1,2,3) should throw" except TypeError: pass try: takes_one_arg() assert False, "takes_one_arg() should throw" except TypeError: pass assert_equal(takes_no_arg(), [None, None]) try: takes_no_arg(1) assert False, "takes_no_arg(1) should throw" except TypeError: pass try: n_ary(-1)(lambda: 1) assert False, "n_ary(-1)(print) should throw" except ValueError: pass assert_equal(n_ary(20)(lambda: 1)(*range(0, 20)), 1)