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