def test_intuitive_physics_all_objects_diagonal_size(): # The fall-down list should contain the move-across objects as well. for definition in util.retrieve_complete_definition_list( [objects.get_intuitive_physics(True)] )[0]: print(f'{definition}\n========================================') assert ( (definition['dimensions']['x'] * math.sqrt(2)) <= (occluders.OCCLUDER_MAX_SCALE_X + util.MAX_SIZE_DIFFERENCE) )
def test_retrieve_complete_definition_list(): list_1 = [{'type': 'ball', 'mass': 1}] actual_1 = retrieve_complete_definition_list([list_1])[0] assert len(actual_1) == 1 list_2 = [{'type': 'ball', 'chooseSize': [{'mass': 1}, {'mass': 2}]}] actual_2 = retrieve_complete_definition_list([list_2])[0] assert len(actual_2) == 2 list_3 = [ {'type': 'sofa'}, {'type': 'ball', 'chooseSize': [{'mass': 1}, {'mass': 2}]} ] actual_3 = retrieve_complete_definition_list([list_3])[0] assert len(actual_3) == 3 list_4 = [ {'type': 'sofa', 'chooseSize': [{'mass': 1}, {'mass': 3}]}, {'type': 'ball', 'chooseSize': [{'mass': 1}, {'mass': 2}]} ] actual_4 = retrieve_complete_definition_list([list_4])[0] assert len(actual_4) == 4 list_5 = [{'chooseType': [{'type': 'sphere'}, {'type': 'cube'}]}] actual_5 = retrieve_complete_definition_list([list_5])[0] assert len(actual_5) == 2 list_6 = [ {'type': 'sofa'}, {'chooseType': [{'type': 'sphere'}, {'type': 'cube'}]} ] actual_6 = retrieve_complete_definition_list([list_6])[0] assert len(actual_6) == 3 list_7 = [ {'chooseType': [{'type': 'ball'}, {'type': 'sofa'}]}, {'chooseType': [{'type': 'sphere'}, {'type': 'cube'}]} ] actual_7 = retrieve_complete_definition_list([list_7])[0] assert len(actual_7) == 4 list_8 = [{ 'chooseMaterial': [ {'materialCategory': ['metal']}, {'materialCategory': ['plastic']} ], 'chooseSize': [{'mass': 1}, {'mass': 2}], 'chooseType': [{'type': 'ball'}, {'type': 'sofa'}] }] actual_8 = retrieve_complete_definition_list([list_8])[0] assert len(actual_8) == 8
def test_intuitive_physics_move_across_all_objects_untrained_shapes(): definition_list = util.retrieve_complete_definition_list( [objects.get_intuitive_physics(False)] )[0] trained_list = util.retrieve_trained_definition_list([definition_list])[0] untrained_list = util.retrieve_untrained_definition_list( [definition_list], tags.SCENE.UNTRAINED_SHAPE )[0] for definition_1 in trained_list: option_list = [ definition_2 for definition_2 in untrained_list if util.is_similar_except_in_shape(definition_1, definition_2, True) ] assert len(option_list) >= 2
def test_intuitive_physics_fall_down_complex_objects_untrained_sizes(): definition_list = util.retrieve_complete_definition_list( [objects.get_intuitive_physics(True, False, True)] )[0] trained_list = util.retrieve_trained_definition_list([definition_list])[0] untrained_list = util.retrieve_untrained_definition_list( [definition_list], tags.SCENE.UNTRAINED_SIZE )[0] for definition_1 in trained_list: option_list = [ definition_2 for definition_2 in untrained_list if util.is_similar_except_in_size(definition_1, definition_2, True) ] # We want at least two possible untrained objects. assert len(option_list) >= 2
def test_retrieve_complete_definition_list_nested_list(): list_1 = [ [{'chooseType': [{'type': 'ball'}, {'type': 'sofa'}]}], [{'chooseType': [{'type': 'sphere'}, {'type': 'cube'}]}] ] actual_1 = retrieve_complete_definition_list(list_1) assert len(actual_1) == 2 assert len(actual_1[0]) == 2 assert len(actual_1[1]) == 2 type_list_a = [item['type'] for item in actual_1[0]] type_list_b = [item['type'] for item in actual_1[1]] assert ( ( 'ball' in type_list_a and 'sofa' in type_list_a and 'sphere' in type_list_b and 'cube' in type_list_b ) or ( 'ball' in type_list_b and 'sofa' in type_list_b and 'sphere' in type_list_a and 'cube' in type_list_a ) )
def test_all_objects_have_expected_properties(): for definition_list in util.retrieve_complete_definition_list( objects.get(objects.ObjectDefinitionList.ALL) ): for object_definition in definition_list: print(f'{object_definition["type"]}') assert 'type' in object_definition assert 'size' in object_definition assert 'shape' in object_definition assert 'mass' in object_definition assert 'attributes' in object_definition assert 'dimensions' in object_definition assert 'materialCategory' in object_definition assert 'salientMaterials' in object_definition if len(object_definition['materialCategory']) == 0: assert 'color' in object_definition assert 'info' not in object_definition if 'massMultiplier' in object_definition: if object_definition['massMultiplier'] < 1: print('[ERROR] Mass multiplier < 1 will cause ' 'intermittent errors in other parts of the code') assert False
def test_retrieve_complete_definition_list_choose_material(): definition_list = [{ 'type': 'metal_thing', 'chooseMaterial': [{'materialCategory': ['metal']}] }, { 'type': 'plastic_thing', 'chooseMaterial': [{'materialCategory': ['plastic']}] }, { 'type': 'rubber_thing', 'chooseMaterial': [{'materialCategory': ['rubber']}] }, { 'type': 'wood_thing', 'chooseMaterial': [{'materialCategory': ['wood']}] }, { 'type': 'other_thing', 'chooseMaterial': [ {'materialCategory': ['metal']}, {'materialCategory': ['plastic']}, {'materialCategory': ['rubber']}, {'materialCategory': ['wood']} ] }] actual_1 = retrieve_complete_definition_list([definition_list])[0] assert len(actual_1) == 8 metal = [item for item in actual_1 if item['type'] == 'metal_thing'] assert len(metal) == 1 assert metal[0]['materialCategory'] == ['metal'] assert 'materials' not in metal[0] plastic = [item for item in actual_1 if item['type'] == 'plastic_thing'] assert len(plastic) == 1 assert plastic[0]['materialCategory'] == ['plastic'] assert 'materials' not in plastic[0] rubber = [item for item in actual_1 if item['type'] == 'rubber_thing'] assert len(rubber) == 1 assert rubber[0]['materialCategory'] == ['rubber'] assert 'materials' not in rubber[0] wood = [item for item in actual_1 if item['type'] == 'wood_thing'] assert len(wood) == 1 assert wood[0]['materialCategory'] == ['wood'] assert 'materials' not in wood[0] other_material_list = ['metal', 'plastic', 'rubber', 'wood'] other = [item for item in actual_1 if item['type'] == 'other_thing'] assert len(other) == 4 assert other[0]['materialCategory'][0] in other_material_list other_material_list.remove(other[0]['materialCategory'][0]) assert 'materials' not in other[0] assert other[1]['materialCategory'][0] in other_material_list other_material_list.remove(other[1]['materialCategory'][0]) assert 'materials' not in other[1] assert other[2]['materialCategory'][0] in other_material_list other_material_list.remove(other[2]['materialCategory'][0]) assert 'materials' not in other[2] assert other[3]['materialCategory'][0] in other_material_list other_material_list.remove(other[3]['materialCategory'][0]) assert 'materials' not in other[3]
import random import materials import objects from util import finalize_object_definition, instantiate_object, \ random_real, move_to_location, retrieve_complete_definition_list, \ retrieve_trained_definition_list, retrieve_untrained_definition_list, \ is_similar_except_in_color, is_similar_except_in_shape, \ is_similar_except_in_size, choose_distractor_definition ALL_DEFINITIONS = [ definition for definition_list in retrieve_complete_definition_list( objects.get(objects.ObjectDefinitionList.ALL) ) for definition in definition_list ] PACIFIER = { "type": "pacifier", "color": "blue", "shape": "pacifier", "size": "tiny", "salientMaterials": ["plastic"], "attributes": ["moveable", "pickupable"], "dimensions": { "x": 0.07, "y": 0.04, "z": 0.05 }, "mass": 0.125, "offset": {
'z': 0 }, 'dimensions': { 'x': 1, 'y': 1, 'z': 1 } }] } PICKUPABLE_OBJECTS_WITHOUT_CONTAINMENTS = [ 'duck_on_wheels', 'chair_1', 'chair_2', 'table_1', 'table_3' ] CONTAINER_DEFINITIONS = [ definition for definition_list in util.retrieve_complete_definition_list( objects.get(objects.ObjectDefinitionList.CONTAINERS)) for definition in definition_list ] PICKUPABLE_DEFINITIONS = [ definition for definition_list in util.retrieve_complete_definition_list( objects.get(objects.ObjectDefinitionList.PICKUPABLES)) for definition in definition_list ] def get_valid_containments(object_a, object_b=None): valid_containments = [] for definition in CONTAINER_DEFINITIONS: if object_b: containment = can_contain_both(definition, object_a, object_b)