def test_applicative_should_call_memoize_saved_value(lazy_spy): lazy = Lazy(lazy_spy.fn) value1 = lazy.get() assert lazy_spy.fn.call_count == 1 value2 = lazy.get() assert lazy_spy.fn.call_count == 1 assert value1 is value2
def test_applicative_eq_evaluated(): lazy1 = Lazy(fn) lazy2 = Lazy(fn) lazy1.get() assert lazy1 != lazy2 lazy2.get() assert lazy1 == lazy2
def test_applicative_eq_value(): lazy1 = Lazy(random) lazy2 = Lazy(random) lazy1.get() lazy2.get() assert lazy1 == lazy1 assert lazy2 == lazy2 assert lazy1 != lazy2
def test_applicative_should_call_stored_function_during_fold_method_call( lazy_spy): applicative = Lazy(lazy_spy.fn) assert lazy_spy.fn.call_count == 0 assert applicative.get() == 42 assert lazy_spy.fn.call_count == 1
def test_applicative_should_not_call_mapper_until_call_get(lazy_spy): applicative = Lazy(lazy_spy.fn).map(lazy_spy.mapper) assert lazy_spy.fn.call_count == 0 assert lazy_spy.mapper.call_count == 0 assert applicative.get() == 43 assert lazy_spy.fn.call_count == 1 assert lazy_spy.mapper.call_count == 1
def test_applicative_should_not_call_binder_until_call_get(lazy_spy): lazy = Lazy(lazy_spy.fn) assert lazy_spy.fn.call_count == 0 assert lazy_spy.binder.call_count == 0 lazy = lazy.bind(lazy_spy.binder) assert lazy_spy.fn.call_count == 0 assert lazy_spy.binder.call_count == 0 result = lazy.get() assert lazy_spy.fn.call_count == 1 assert lazy_spy.binder.call_count == 1 assert result == 43