def check_simpack(simpack): _test_settings = simpack._test_settings simpack_grokker = SimpackGrokker(simpack) # Test the caching: assert simpack_grokker is SimpackGrokker(simpack) step_profile = simpack_grokker.build_step_profile() assert step_profile.function == simpack_grokker.default_step_function assert isinstance(step_profile, garlicsim.misc.StepProfile) assert (not step_profile.args) and (not step_profile.kwargs) assert len(simpack_grokker.all_step_functions) == \ _test_settings.N_STEP_FUNCTIONS state = simpack.State.create_root() assert SimpackGrokker.create_from_state(state) is simpack_grokker assert simpack_grokker.available_cruncher_types == \ simpack._test_settings.CRUNCHERS_LIST assert simpack_grokker.available_cruncher_types == \ [cruncher for cruncher, availability in simpack_grokker.cruncher_types_availability.items() if availability] assert all( issubclass(cruncher, garlicsim.asynchronous_crunching.BaseCruncher) for cruncher in simpack_grokker.cruncher_types_availability.keys()) assert simpack_grokker.default_step_function == \ _test_settings.DEFAULT_STEP_FUNCTION assert simpack_grokker.history_dependent == \ _test_settings.HISTORY_DEPENDENT settings = simpack_grokker.settings assert isinstance(settings, Settings) assert callable(settings.DETERMINISM_FUNCTION) if not simpack_grokker.history_dependent: assert isinstance(simpack_grokker.step(state, step_profile), simpack.State) iterator = simpack_grokker.get_step_iterator(state, step_profile) assert iterator.__iter__() is iterator step_types = simpack_grokker.step_functions_by_type.keys() assert all(issubclass(step_type, BaseStep) for step_type in step_types) # Fetched in a different way than `simpack_grokker.all_step_functions`: all_step_functions = sequence_tools.flatten( simpack_grokker.step_functions_by_type.values()) assert all( issubclass(StepType.get_step_type(step_function), BaseStep) for step_function in all_step_functions) assert len(all_step_functions) == _test_settings.N_STEP_FUNCTIONS
def test_all_sizes(): '''Test using `n=None` so combinations of all sizes are returned.''' assert list(combinations(xrange(4))) == sequence_tools.flatten( list(combinations(xrange(4), i)) for i in xrange(1, 4 + 1))
def check_simpack(simpack): _test_settings = simpack._test_settings simpack_grokker = SimpackGrokker(simpack) # Test the caching: assert simpack_grokker is SimpackGrokker(simpack) step_profile = simpack_grokker.build_step_profile() assert step_profile.function == simpack_grokker.default_step_function assert isinstance(step_profile, garlicsim.misc.StepProfile) assert (not step_profile.args) and (not step_profile.kwargs) assert len(simpack_grokker.all_step_functions) == \ _test_settings.N_STEP_FUNCTIONS state = simpack.State.create_root() assert SimpackGrokker.create_from_state(state) is simpack_grokker assert simpack_grokker.available_cruncher_types == \ simpack._test_settings.CRUNCHERS_LIST assert simpack_grokker.available_cruncher_types == \ [cruncher for cruncher, availability in list(list(simpack_grokker.cruncher_types_availability.items())) if availability] assert all( issubclass(cruncher, garlicsim.asynchronous_crunching.BaseCruncher) for cruncher in list(list(simpack_grokker.cruncher_types_availability.keys())) ) assert simpack_grokker.default_step_function == \ _test_settings.DEFAULT_STEP_FUNCTION assert simpack_grokker.history_dependent == \ _test_settings.HISTORY_DEPENDENT settings = simpack_grokker.settings assert isinstance(settings, Settings) assert isinstance(settings.DETERMINISM_FUNCTION, collections.Callable) if not simpack_grokker.history_dependent: assert isinstance(simpack_grokker.step(state, step_profile), simpack.State) iterator = simpack_grokker.get_step_iterator(state, step_profile) assert iterator.__iter__() is iterator step_types = list(list(simpack_grokker.step_functions_by_type.keys())) assert all(issubclass(step_type, BaseStep) for step_type in step_types) # Fetched in a different way than `simpack_grokker.all_step_functions`: all_step_functions = sequence_tools.flatten( list(list(simpack_grokker.step_functions_by_type.values())) ) assert all( issubclass(StepType.get_step_type(step_function), BaseStep) for step_function in all_step_functions ) assert len(all_step_functions) == _test_settings.N_STEP_FUNCTIONS
def test_all_sizes(): '''Test using `n=None` so combinations of all sizes are returned.''' assert list(combinations(xrange(4))) == sequence_tools.flatten( list(combinations(xrange(4), i)) for i in xrange(1, 4+1) )