def test_group(module, EXAMPLE): assert_hasattr(module, 'Group') assert_is_instance(module.Group, type) shared = module.Shared.from_dict(EXAMPLE['shared']) values = EXAMPLE['values'] for value in values: shared.add_value(value) group1 = module.Group() group1.init(shared) for value in values: group1.add_value(shared, value) group2 = module.Group.from_values(shared, values) assert_close(group1.dump(), group2.dump()) group = module.Group.from_values(shared, values) dumped = group.dump() group.init(shared) group.load(dumped) assert_close(group.dump(), dumped) for value in values: group2.remove_value(shared, value) assert_not_equal(group1, group2) group2.merge(shared, group1) for value in values: group1.score_value(shared, value) for _ in xrange(10): value = group1.sample_value(shared) group1.score_value(shared, value) module.sample_group(shared, 10) group1.score_data(shared) group2.score_data(shared)
def test_value(module, EXAMPLE): assert_hasattr(module, 'Value') assert_is_instance(module.Value, type) values = EXAMPLE['values'] for value in values: assert_is_instance(value, module.Value)
def iter_examples(Model): assert_hasattr(Model, 'EXAMPLES') EXAMPLES = Model.EXAMPLES assert_is_instance(EXAMPLES, list) assert_true(EXAMPLES, 'no examples provided') for i, EXAMPLE in enumerate(EXAMPLES): print 'example {}/{}'.format(1 + i, len(Model.EXAMPLES)) yield EXAMPLE
def iter_examples(Model): assert_hasattr(Model, "EXAMPLES") EXAMPLES = Model.EXAMPLES assert_is_instance(EXAMPLES, list) assert_true(EXAMPLES, "no examples provided") for i, EXAMPLE in enumerate(EXAMPLES): print "example {}/{}".format(1 + i, len(Model.EXAMPLES)) yield EXAMPLE
def iter_examples(module): assert_hasattr(module, 'EXAMPLES') EXAMPLES = module.EXAMPLES assert_is_instance(EXAMPLES, list) assert_true(EXAMPLES, 'no examples provided') for i, EXAMPLE in enumerate(EXAMPLES): print 'example {}/{}'.format(1 + i, len(EXAMPLES)) assert_in('shared', EXAMPLE) assert_in('values', EXAMPLE) values = EXAMPLE['values'] assert_is_instance(values, list) count = len(values) assert_true( count >= 7, 'Add more example values (expected >= 7, found {})'.format(count)) yield EXAMPLE
def test_shared(module, EXAMPLE): assert_hasattr(module, 'Shared') assert_is_instance(module.Shared, type) shared1 = module.Shared.from_dict(EXAMPLE['shared']) shared2 = module.Shared.from_dict(EXAMPLE['shared']) assert_close(shared1.dump(), EXAMPLE['shared']) values = EXAMPLE['values'] seed_all(0) for value in values: shared1.add_value(value) seed_all(0) for value in values: shared2.add_value(value) assert_close(shared1.dump(), shared2.dump()) for value in values: shared1.remove_value(value) assert_close(shared1.dump(), EXAMPLE['shared'])
def test_interface(Model, EXAMPLE): for typename in ['Value', 'Group']: assert_hasattr(Model, typename) assert_is_instance(getattr(Model, typename), type) model = Model.model_load(EXAMPLE['model']) values = EXAMPLE['values'] for value in values: assert_is_instance(value, Model.Value) group1 = model.Group() model.group_init(group1) for value in values: model.group_add_value(group1, value) group2 = model.group_create(values) assert_close(group1.dump(), group2.dump()) group = model.group_create(values) dumped = group.dump() model.group_init(group) group.load(dumped) assert_close(group.dump(), dumped) for value in values: model.group_remove_value(group2, value) assert_not_equal(group1, group2) model.group_merge(group2, group1) for value in values: model.score_value(group1, value) for _ in xrange(10): value = model.sample_value(group1) model.score_value(group1, value) model.sample_group(10) model.score_group(group1) model.score_group(group2) assert_close(model.dump(), EXAMPLE['model']) assert_close(model.dump(), Model.model_dump(model)) assert_close(group1.dump(), Model.group_dump(group1))
def test_one_model(name): module = MODULES[name] assert_hasattr(module, 'Shared') for EXAMPLE in iter_examples(module): test_fun(module, EXAMPLE)
def test_one_model(name): module = MODULES[name] assert_hasattr(module, 'Model') Model = module.Model for EXAMPLE in iter_examples(Model): test_fun(Model, EXAMPLE)