def test_stack_safety(self): with recursion_limit(100): sequence([Just(v) for v in range(500)])
def test_get_existing_key(d): d = d.set('key', 'value') assert d['key'] == 'value' assert d.get('key') == Just('value')
def test_just_bool(self, value): assert bool(Just(value))
def test_sequence(self): assert sequence([Just(v) for v in range(3)]) == Just((0, 1, 2))
def test_just_or_else(self, value): assert Just(value).or_else(None) == value
def test_maybe_decorater(self): maybe_int = maybe(int) assert maybe_int('1') == Just(1) assert maybe_int('whoops') == Nothing()
def _test_just_identity_law(self, value): assert Just(value).map(identity) == Just(value)
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)
def _test_just_inequality(self, value): assert Just(value) != Nothing()
def _test_nothing_inequality(self, first, second): assume(first != second) assert Just(first) != Just(second)
def _test_just_equality(self, value): assert Just(value) == Just(value)
def test_left_identity_law(self, value, f: Unary[Any, Maybe]): assert Just(value).and_then(f) == f(value)
def test_for_each(self): assert for_each(Just, range(3)) == Just((0, 1, 2))
def test_filter(self): assert filter_(lambda v: Just(v % 2 == 0), range(3)) == Just((0, 2))
def test_gather(self): assert gather([Just(v) for v in range(3)]) == Just((0, 1, 2))