Ejemplo n.º 1
0
def test_retrieve_trained_definition_list():
    definition_list = [{
        'type': 'a'
    }, {
        'type': 'b',
        'untrainedCategory': True
    }, {
        'type': 'c',
        'untrainedColor': True
    }, {
        'type': 'd',
        'untrainedCombination': True
    }, {
        'type': 'e',
        'untrainedShape': True
    }, {
        'type': 'f',
        'untrainedSize': True
    }, {
        'type': 'g',
        'untrainedCategory': True,
        'untrainedColor': True,
        'untrainedCombination': True,
        'untrainedShape': True,
        'untrainedSize': True
    }, {
        'type': 'h'
    }]

    actual_1 = retrieve_trained_definition_list([definition_list])[0]
    assert len(actual_1) == 2
    assert actual_1[0]['type'] == 'a'
    assert actual_1[1]['type'] == 'h'
Ejemplo n.º 2
0
 def choose_definition(
     self,
     must_be_pickupable: bool = False
 ) -> Dict[str, Any]:
     """Choose and return an object definition."""
     definition_list = random.choice(retrieve_trained_definition_list(
         objects.get(objects.ObjectDefinitionList.PICKUPABLES)
         if must_be_pickupable
         else objects.get(objects.ObjectDefinitionList.ALL)
     ))
     # Same chance to pick each object definition from the list.
     definition = finalize_object_definition(random.choice(definition_list))
     # Finalize the material here in case we need to make a confusor.
     return random.choice(finalize_object_materials_and_colors(definition))
Ejemplo n.º 3
0
    def choose_target_definition(self, target_number: int) -> Dict[str, Any]:
        if target_number == 0:
            return self.choose_definition(must_be_pickupable=True)

        if target_number != 1:
            raise exceptions.SceneException(
                f'Expected target with number 0 or 1 but got {target_number}')

        definition_list = random.choice(retrieve_trained_definition_list(
            objects.get(objects.ObjectDefinitionList.STACK_TARGETS)
        ))

        # Same chance to pick each object definition from the list.
        definition = finalize_object_definition(random.choice(definition_list))
        # Finalize the material here in case we need to make a confusor.
        return random.choice(finalize_object_materials_and_colors(definition))
Ejemplo n.º 4
0
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
Ejemplo n.º 5
0
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
Ejemplo n.º 6
0
def test_retrieve_trained_definition_list_occluder_objects():
    assert len(retrieve_trained_definition_list(
        objects.get(objects.ObjectDefinitionList.OCCLUDERS)
    )) > 0
Ejemplo n.º 7
0
def test_retrieve_trained_definition_list_obstacle_objects():
    assert len(retrieve_trained_definition_list(
        objects.get(objects.ObjectDefinitionList.OBSTACLES)
    )) > 0
Ejemplo n.º 8
0
def test_retrieve_trained_definition_list_container_objects():
    assert len(retrieve_trained_definition_list(objects.get(
        objects.ObjectDefinitionList.CONTAINERS)
    )) > 0
Ejemplo n.º 9
0
def test_retrieve_trained_definition_list_all_objects():
    assert len(retrieve_trained_definition_list(objects.get(
        objects.ObjectDefinitionList.ALL)
    )) > 0