Beispiel #1
0
def pipe_test():
    piped = pipe(
        sub2,
        double,
        add10
    )
    assert_equal(piped(100), (100-2)*2+10)
Beispiel #2
0
def compose_test():
    composed = compose(
        sub2,
        double,
        add10
    )
    assert_equal(composed(100), 218)
Beispiel #3
0
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]
Beispiel #4
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])
Beispiel #5
0
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
                     }
                 }})
Beispiel #6
0
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
    })
Beispiel #7
0
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
            }
        }})
Beispiel #8
0
def mean_test():
    assert_equal(mean([3, 5, 7]), 5)
    assert_equal(mean([5, 7, 3]), 5)
Beispiel #9
0
def replace_curry_test():
    assert_equal(replace('a', 'b')('aa'), 'bb')
Beispiel #10
0
def replace_curry_regex_test():
    assert_equal(replace(r'a+', 'b')('aa'), 'b')
Beispiel #11
0
def group_by_no_curry_test():
    assert_equal(group_by(grade, students), students_by_grade)
Beispiel #12
0
def test_apply_curry():
    assert_equal(apply_to(42)(identity), 42)
    assert_equal(apply_to(42)(add(1)), 43)
Beispiel #13
0
def test_path_nocurry():
    assert_equal(path(["a", "b", "c"], test_dict), "foo")
Beispiel #14
0
def find_nocurry_test():
    assert_equal(find(positive, [-2, -1, 0, 1, 2]), 1)
Beispiel #15
0
def match_curry_regex_test():
    assert_equal(match(r"a+")("aa"), ["aa"])
Beispiel #16
0
def test_subtract_curry():
    assert_equal(subtract(4)(3), 1)
Beispiel #17
0
def test_subtract_nocurry():
    assert_equal(subtract(4, 3), 1)
Beispiel #18
0
def test_juxt_nocurry():
    assert_equal(juxt([add, sub])(1, 2), [3, -1])
Beispiel #19
0
def test_identity():
    assert_equal(identity(3), 3)
Beispiel #20
0
def find_last_nocurry_test():
    assert_equal(find_last(positive, [-2, -1, 0, 1, 2, -2]), 2)
Beispiel #21
0
def match_curry_test():
    assert_equal(match("a")("aa"), ["a", "a"])
Beispiel #22
0
def test_path_throws():
    try:
        path([], test_dict)
    except ValueError:
        assert_equal(True, True)
Beispiel #23
0
def not_found_test():
    try:
        find(positive, [])
    except ValueError:
        assert_equal(True, True)
Beispiel #24
0
def item_path_curry_test():
    get_abc = item_path(["a", "b", "c"])
    assert_equal(get_abc(test_dict), "foo")
Beispiel #25
0
def not_found_test():
    assert_equal(find_last(positive, []), None)
Beispiel #26
0
def item_path_throws_test():
    try:
        item_path([], test_dict)
    except ValueError:
        assert_equal(True, True)
Beispiel #27
0
def sum_test():
    assert_equal(sum([1, 2, 3]), 6)
Beispiel #28
0
def item_path_nocurry_test():
    assert_equal(item_path(["a", "b", "c"], test_dict), "foo")
Beispiel #29
0
def test_apply_nocurry():
    assert_equal(apply_to(42, identity), 42)
    assert_equal(apply_to(42, add(1)), 43)
Beispiel #30
0
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)