private void setVariableReferencesOfClonedSprite(Sprite cloneSprite) { DataContainer dataContainer = ProjectManager.getInstance().getCurrentProject().getDataContainer(); List<UserVariable> clonedSpriteVariables = dataContainer.getOrCreateVariableListForSprite(cloneSprite); cloneSprite.updateUserVariableReferencesInUserVariableBricks(clonedSpriteVariables); List<UserVariable> clonedProjectVariables = dataContainer.getProjectVariables(); cloneSprite.updateUserVariableReferencesInUserVariableBricks(clonedProjectVariables); }
private void cloneSpriteVariables(Project currentProject, Sprite cloneSprite) { DataContainer userVariables = currentProject.getDataContainer(); List<UserVariable> originalSpriteVariables = userVariables.getOrCreateVariableListForSprite(this); List<UserVariable> clonedSpriteVariables = userVariables.getOrCreateVariableListForSprite(cloneSprite); for (UserVariable variable : originalSpriteVariables) { clonedSpriteVariables.add(new UserVariable(variable.getName(), variable.getValue())); } }
@Override protected void setUp() { Project project = new Project(null, "testProject"); firstSprite = new SingleSprite("firstSprite"); StartScript startScript = new StartScript(); ChangeSizeByNBrick changeBrick = new ChangeSizeByNBrick(10); firstSprite.addScript(startScript); startScript.addBrick(changeBrick); project.getDefaultScene().addSprite(firstSprite); ProjectManager.getInstance().setProject(project); ProjectManager.getInstance().setCurrentSprite(firstSprite); dataContainer = ProjectManager.getInstance().getCurrentScene().getDataContainer(); dataContainer.addProjectUserList(PROJECT_USER_LIST_NAME); dataContainer.addSpriteUserListToSprite(firstSprite, SPRITE_USER_LIST_NAME); dataContainer.addProjectUserList(PROJECT_USER_LIST_NAME_2); }
public void testFunctionLength() { dataContainer.addProjectUserList(PROJECT_USER_LIST_NAME); dataContainer.getUserList(PROJECT_USER_LIST_NAME, firstSprite).setList(new ArrayList<Object>()); FormulaEditorTestUtil.testSingleParameterFunction( Functions.LENGTH, InternTokenType.USER_LIST, PROJECT_USER_LIST_NAME, (double) 0, firstSprite); dataContainer .getUserList(PROJECT_USER_LIST_NAME, firstSprite) .setList(USER_LIST_VALUES_STRINGS); FormulaEditorTestUtil.testSingleParameterFunction( Functions.LENGTH, InternTokenType.USER_LIST, PROJECT_USER_LIST_NAME, (double) USER_LIST_VALUES_STRINGS_LENGTH_INTERPRETATION_VALUE, firstSprite); ArrayList<Object> userList = new ArrayList<Object>(); userList.add("0"); dataContainer.getUserList(PROJECT_USER_LIST_NAME, firstSprite).setList(userList); FormulaEditorTestUtil.testSingleParameterFunction( Functions.LENGTH, InternTokenType.USER_LIST, PROJECT_USER_LIST_NAME, (double) 1, firstSprite); userList.clear(); userList.add("0.0"); FormulaEditorTestUtil.testSingleParameterFunction( Functions.LENGTH, InternTokenType.USER_LIST, PROJECT_USER_LIST_NAME, (double) 3, firstSprite); FormulaEditorTestUtil.testSingleParameterFunction( Functions.LENGTH, InternTokenType.NUMBER, "0", (double) 1, firstSprite); FormulaEditorTestUtil.testSingleParameterFunction( Functions.LENGTH, InternTokenType.NUMBER, "0.0", (double) 3, firstSprite); }
public void testUserListReset() { dataContainer.addSpriteUserList(SPRITE_USER_LIST_NAME); dataContainer.addSpriteUserList(PROJECT_USER_LIST_NAME_2); dataContainer.addSpriteUserList(PROJECT_USER_LIST_NAME); dataContainer .getUserList(SPRITE_USER_LIST_NAME, firstSprite) .setList(USER_LIST_VALUES_MULTIPLE_NUMBERS); dataContainer .getUserList(PROJECT_USER_LIST_NAME, firstSprite) .setList(USER_LIST_VALUES_MULTIPLE_NUMBERS); dataContainer .getUserList(PROJECT_USER_LIST_NAME_2, firstSprite) .setList(USER_LIST_VALUES_MULTIPLE_NUMBERS); dataContainer.resetAllDataObjects(); assertEquals( "Sprite UserList did not reset", EMPTY_USER_LIST_INTERPRETATION_VALUE, interpretUserList(SPRITE_USER_LIST_NAME)); assertEquals( "Project UserList did not reset", EMPTY_USER_LIST_INTERPRETATION_VALUE, interpretUserList(PROJECT_USER_LIST_NAME)); assertEquals( "Project UserList 2 did not reset", EMPTY_USER_LIST_INTERPRETATION_VALUE, interpretUserList(PROJECT_USER_LIST_NAME_2)); }
public void testUserListInterpretationEmptyList() { dataContainer.getUserList(PROJECT_USER_LIST_NAME, firstSprite).getList().clear(); assertEquals( "Formula interpretation of List is not as expected", EMPTY_USER_LIST_INTERPRETATION_VALUE, (Double) interpretUserList(PROJECT_USER_LIST_NAME), DELTA); }
public void testUserListInterpretationStringsAndNumbers() { dataContainer .getUserList(PROJECT_USER_LIST_NAME, firstSprite) .setList(USER_LIST_VALUES_STRINGS_AND_NUMBERS); assertEquals( "Formula interpretation of List is not as expected", USER_LIST_VALUES_STRINGS_AND_NUMBERS_INTERPRETATION_VALUE, interpretUserList(PROJECT_USER_LIST_NAME)); }
public void testUserListInterpretationMultipleNumberString() { dataContainer .getUserList(PROJECT_USER_LIST_NAME, firstSprite) .setList(USER_LIST_VALUES_MULTIPLE_NUMBER_STRING); assertEquals( "Formula interpretation of List is not as expected", USER_LIST_VALUES_MULTIPLE_NUMBER_STRING_INTERPRETATION_VALUE, interpretUserList(PROJECT_USER_LIST_NAME)); }
public void testFunctionNumberOfItems() { dataContainer.addProjectUserList(PROJECT_USER_LIST_NAME); FormulaEditorTestUtil.testSingleParameterFunction( Functions.NUMBER_OF_ITEMS, InternTokenType.USER_LIST, PROJECT_USER_LIST_NAME, (double) 0, firstSprite); dataContainer .getUserList(PROJECT_USER_LIST_NAME, firstSprite) .setList(USER_LIST_VALUES_STRINGS); FormulaEditorTestUtil.testSingleParameterFunction( Functions.LENGTH, InternTokenType.USER_LIST, PROJECT_USER_LIST_NAME, (double) USER_LIST_VALUES_STRINGS_LENGTH_INTERPRETATION_VALUE, firstSprite); }
@Override protected void begin() { DataContainer dataContainer = ProjectManager.getInstance().getCurrentProject().getDataContainer(); Sprite currentSprite = ProjectManager.getInstance().getCurrentSprite(); List<UserVariable> variableList = dataContainer.getProjectVariables(); Map<Sprite, List<UserVariable>> spriteVariableMap = dataContainer.getSpriteVariableMap(); setVariablesVisible(variableList); if (currentSprite != null) { List<UserVariable> spriteVariableList = spriteVariableMap.get(currentSprite); setVariablesVisible(spriteVariableList); } if (userBrick != null) { List<UserVariable> userBrickVariableList = dataContainer.getOrCreateVariableListForUserBrick(userBrick); setVariablesVisible(userBrickVariableList); } }
public void testFunctionContains() { dataContainer.addProjectUserList(PROJECT_USER_LIST_NAME); dataContainer .getUserList(PROJECT_USER_LIST_NAME, firstSprite) .setList(USER_LIST_VALUES_MULTIPLE_NUMBERS); dataContainer.addProjectUserVariable(PROJECT_USER_VARIABLE); FormulaEditorTestUtil.testDoubleParameterFunction( Functions.CONTAINS, InternTokenType.USER_LIST, PROJECT_USER_LIST_NAME, InternTokenType.NUMBER, "1", 1d, firstSprite); FormulaEditorTestUtil.testDoubleParameterFunction( Functions.CONTAINS, InternTokenType.USER_LIST, PROJECT_USER_LIST_NAME, InternTokenType.STRING, "1", 1d, firstSprite); FormulaEditorTestUtil.testDoubleParameterFunction( Functions.CONTAINS, InternTokenType.USER_LIST, PROJECT_USER_LIST_NAME, InternTokenType.STRING, "1.00", 1d, firstSprite); FormulaEditorTestUtil.testDoubleParameterFunction( Functions.CONTAINS, InternTokenType.USER_LIST, PROJECT_USER_LIST_NAME, InternTokenType.NUMBER, "0", 0d, firstSprite); dataContainer .getUserList(PROJECT_USER_LIST_NAME, firstSprite) .setList(USER_LIST_VALUES_STRINGS_AND_NUMBERS); FormulaEditorTestUtil.testDoubleParameterFunction( Functions.CONTAINS, InternTokenType.USER_LIST, PROJECT_USER_LIST_NAME, InternTokenType.STRING, "Hello", 1d, firstSprite); dataContainer.getUserVariable(PROJECT_USER_VARIABLE, firstSprite).setValue("Hello"); FormulaEditorTestUtil.testDoubleParameterFunction( Functions.CONTAINS, InternTokenType.USER_LIST, PROJECT_USER_LIST_NAME, InternTokenType.USER_VARIABLE, PROJECT_USER_VARIABLE, 1d, firstSprite); }
public void testFunctionListItem() { dataContainer.addSpriteUserList(PROJECT_USER_LIST_NAME); dataContainer .getUserList(PROJECT_USER_LIST_NAME, firstSprite) .setList(USER_LIST_VALUES_MULTIPLE_NUMBERS); dataContainer.addProjectUserVariable(PROJECT_USER_VARIABLE); String index = "1"; FormulaEditorTestUtil.testDoubleParameterFunction( Functions.LIST_ITEM, InternTokenType.NUMBER, index, InternTokenType.USER_LIST, PROJECT_USER_LIST_NAME, 1.0, firstSprite); index = "0"; FormulaEditorTestUtil.testDoubleParameterFunction( Functions.LIST_ITEM, InternTokenType.NUMBER, index, InternTokenType.USER_LIST, PROJECT_USER_LIST_NAME, "", firstSprite); index = "4"; FormulaEditorTestUtil.testDoubleParameterFunction( Functions.LIST_ITEM, InternTokenType.NUMBER, index, InternTokenType.USER_LIST, PROJECT_USER_LIST_NAME, "", firstSprite); index = "1.4"; FormulaEditorTestUtil.testDoubleParameterFunction( Functions.LIST_ITEM, InternTokenType.NUMBER, index, InternTokenType.USER_LIST, PROJECT_USER_LIST_NAME, 1.0, firstSprite); index = "1.0"; FormulaEditorTestUtil.testDoubleParameterFunction( Functions.LIST_ITEM, InternTokenType.STRING, index, InternTokenType.USER_LIST, PROJECT_USER_LIST_NAME, 1.0, firstSprite); dataContainer.getUserVariable(PROJECT_USER_VARIABLE, firstSprite).setValue("1"); FormulaEditorTestUtil.testDoubleParameterFunction( Functions.LIST_ITEM, InternTokenType.USER_VARIABLE, PROJECT_USER_VARIABLE, InternTokenType.USER_LIST, PROJECT_USER_LIST_NAME, 1.0, firstSprite); dataContainer.getUserVariable(PROJECT_USER_VARIABLE, firstSprite).setValue("0"); FormulaEditorTestUtil.testDoubleParameterFunction( Functions.LIST_ITEM, InternTokenType.USER_VARIABLE, PROJECT_USER_VARIABLE, InternTokenType.USER_LIST, PROJECT_USER_LIST_NAME, "", firstSprite); dataContainer.getUserVariable(PROJECT_USER_VARIABLE, firstSprite).setValue("4"); FormulaEditorTestUtil.testDoubleParameterFunction( Functions.LIST_ITEM, InternTokenType.USER_VARIABLE, PROJECT_USER_VARIABLE, InternTokenType.USER_LIST, PROJECT_USER_LIST_NAME, "", firstSprite); dataContainer.getUserVariable(PROJECT_USER_VARIABLE, firstSprite).setValue(1d); FormulaEditorTestUtil.testDoubleParameterFunction( Functions.LIST_ITEM, InternTokenType.USER_VARIABLE, PROJECT_USER_VARIABLE, InternTokenType.USER_LIST, PROJECT_USER_LIST_NAME, 1.0, firstSprite); dataContainer.getUserVariable(PROJECT_USER_VARIABLE, firstSprite).setValue(0d); FormulaEditorTestUtil.testDoubleParameterFunction( Functions.LIST_ITEM, InternTokenType.USER_VARIABLE, PROJECT_USER_VARIABLE, InternTokenType.USER_LIST, PROJECT_USER_LIST_NAME, "", firstSprite); dataContainer.getUserVariable(PROJECT_USER_VARIABLE, firstSprite).setValue(4d); FormulaEditorTestUtil.testDoubleParameterFunction( Functions.LIST_ITEM, InternTokenType.USER_VARIABLE, PROJECT_USER_VARIABLE, InternTokenType.USER_LIST, PROJECT_USER_LIST_NAME, "", firstSprite); }