Example #1
0
def test_cond():
    fn = cond([equals(0), const("water freezes at 0")],
              [equals(100), const("water boils at 100")],
              [T, lambda temp: "nothing special happens at {}".format(temp)])
    assert fn(0) == "water freezes at 0"
    assert fn(100) == "water boils at 100"
    assert fn(50) == "nothing special happens at 50"
def test_falsey():
    return all(equals(1), [1, 2]) == False
def test_truthy():
    return all(equals(1), [1, 1]) == True
 def test_truthy(self, pred, input, expected):
     assert any(equals(pred), input) == expected
def test_string():
    assert equals("a", "a") == True
    assert equals("a", "b") == False
def test_nested_dict():
    nested = equals({"one": 1, "two": {"three": 3}})
    assert nested({"one": 1, "two": {"three": 3}}) == True
    assert nested({"one": {"two": 2}, "three": 3}) == False
def test_nested_list():
    nested = equals([1, [2, [{"three": 3}]]])
    assert nested([1, [2, [{"three": 3}]]]) == True
    assert nested([1, [2, [{"three": 3}, {"four": 4}]]]) == False
def test_num():
    assert equals(1, 1) == True
    assert equals(1, 2) == False
def test_equals_set():
    assert equals(set(), set()) == True
    assert equals(set(), {1}) == False
def test_equals_dict():
    assert equals(dict(), dict()) == True
    assert equals(dict(), {"one": 1}) == False
def test_equals_tuple():
    assert equals(tuple(), tuple()) == True
    assert equals(tuple(), (1)) == False
def test_equals_list():
    assert equals(list(), list()) == True
    assert equals(list(), [1]) == False
Example #13
0
def test_if_else_multi():
    is_jim = if_else(equals("jim"), const("hi jim"), const("hi other"))
    who_is = if_else(equals("pam"), const("hi pam"), is_jim)
    assert who_is("jim") == "hi jim"
    assert who_is("pam") == "hi pam"
    assert who_is("other") == "hi other"
Example #14
0
def test_if_else():
    is_jim = if_else(equals("jim"), const("halpert"), identity)
    assert is_jim("jim") == "halpert"
    assert is_jim("pam") == "pam"
def test_complement():
    is_zero = equals(0)
    not_zero = complement(is_zero)
    assert not_zero(0) == False
    assert not_zero(1) == True