Beispiel #1
0
 def test_stack_safety(self):
     with recursion_limit(100):
         sequence([Just(v) for v in range(500)])
Beispiel #2
0
def test_get_existing_key(d):
    d = d.set('key', 'value')
    assert d['key'] == 'value'
    assert d.get('key') == Just('value')
Beispiel #3
0
 def test_just_bool(self, value):
     assert bool(Just(value))
Beispiel #4
0
 def test_sequence(self):
     assert sequence([Just(v) for v in range(3)]) == Just((0, 1, 2))
Beispiel #5
0
 def test_just_or_else(self, value):
     assert Just(value).or_else(None) == value
Beispiel #6
0
 def test_maybe_decorater(self):
     maybe_int = maybe(int)
     assert maybe_int('1') == Just(1)
     assert maybe_int('whoops') == Nothing()
Beispiel #7
0
 def _test_just_identity_law(self, value):
     assert Just(value).map(identity) == Just(value)
Beispiel #8
0
 def test_composition_law(self, f: Unary, g: Unary, value):
     h = compose(f, g)
     assert Just(value).map(h) == Just(value).map(g).map(f)
     assert Nothing().map(h) == Nothing().map(g).map(f)
Beispiel #9
0
 def _test_just_inequality(self, value):
     assert Just(value) != Nothing()
Beispiel #10
0
 def _test_nothing_inequality(self, first, second):
     assume(first != second)
     assert Just(first) != Just(second)
Beispiel #11
0
 def _test_just_equality(self, value):
     assert Just(value) == Just(value)
Beispiel #12
0
 def test_left_identity_law(self, value, f: Unary[Any, Maybe]):
     assert Just(value).and_then(f) == f(value)
Beispiel #13
0
 def test_for_each(self):
     assert for_each(Just, range(3)) == Just((0, 1, 2))
Beispiel #14
0
 def test_filter(self):
     assert filter_(lambda v: Just(v % 2 == 0), range(3)) == Just((0, 2))
Beispiel #15
0
 def test_gather(self):
     assert gather([Just(v) for v in range(3)]) == Just((0, 1, 2))