def _simulation_gen(): f_in = io.BytesIO() f_out = io.BytesIO() with Core(f_tee=(f_in, f_out)) as core: response = simulation.run( core, simulation.Request( name='random', alternatives=['A', 'B', 'C', 'D', 'E'], gen_menus=simulation.GenMenus( generator=simulation.Exhaustive(), defaults=False, ), gen_choices=simulation.Uniform( forced_choice=True, multiple_choice=False, ), preserve_deferrals=False, )) with open('in.bin', 'wb') as f: f.write(f_in.getbuffer()) with open('out.bin', 'wb') as f: f.write(f_out.getbuffer())
def value(self) -> 'simulation.GenMenus': assert self.alt_count is not None generator: simulation.MenuGenerator defaults: bool if self.rbExhaustive.isChecked(): generator = simulation.Exhaustive() elif self.rbSampleWithReplacement.isChecked(): generator = simulation.SampleWithReplacement( menu_count=self.sbSampleWithReplacementCount.value(), ) elif self.rbBinary.isChecked(): generator = simulation.Binary() else: raise gui.ValidationError('please select a choice distribution') if self.cbDefault.currentIndex() == 0: defaults = False elif self.cbDefault.currentIndex() == 1: defaults = True else: raise gui.ValidationError('unrecognised choice of defaults') return simulation.GenMenus( generator=generator, defaults=defaults, )
def test_simulation(nsubjects=256, f_mock=None): with Core(f_mock=f_mock) as core: response = simulation.run( core, simulation.Request( name='random', alternatives=('A', 'B', 'C', 'D', 'E'), gen_menus=simulation.GenMenus( generator=simulation.Exhaustive(), defaults=False, ), gen_choices=simulation.Uniform( forced_choice=True, multiple_choice=False, ), )) assert len(response.subject_packed) == 223