@Test public void testGetAddNewFunctionModel() { CompositeFunction compositeFunction = new CompositeFunction(); Add add = new Add(); add.addFunction(new Gaussian()); compositeFunction.addFunction(add); FunctionModelRoot modelRoot = new FunctionModelRoot(compositeFunction, provider); assertTreeLooksLike( modelRoot, Node.ADD(Node.GAUSSIAN, Node.ADD_NEW_FUNCTION), Node.ADD_NEW_FUNCTION); // Positive tests AddNewFunctionModel[] addNewFunctionModels = modelRoot.getAddNewFunctionModel(compositeFunction); assertEquals(1, addNewFunctionModels.length); assertTrue(compositeFunction == addNewFunctionModels[0].getParent()); addNewFunctionModels = modelRoot.getAddNewFunctionModel(add); assertEquals(1, addNewFunctionModels.length); assertTrue(add == addNewFunctionModels[0].getParent()); // Positive tests using non-original operator Add addOther = new Add(); addOther.addFunction(new Gaussian()); addNewFunctionModels = modelRoot.getAddNewFunctionModel(addOther); assertEquals(1, addNewFunctionModels.length); // make sure we have been returned an instance of the add we put in the // composite function assertTrue(add == addNewFunctionModels[0].getParent()); // Failed to find tests assertEquals(0, modelRoot.getAddNewFunctionModel(new Add()).length); assertEquals(0, modelRoot.getAddNewFunctionModel(new Subtract()).length); assertEquals(0, modelRoot.getAddNewFunctionModel(new CompositeFunction()).length); // Find multiple tests Add add2 = new Add(); add2.addFunction(new Gaussian()); compositeFunction.addFunction(add2); assertTreeLooksLike( modelRoot, Node.ADD(Node.GAUSSIAN, Node.ADD_NEW_FUNCTION), Node.ADD(Node.GAUSSIAN, Node.ADD_NEW_FUNCTION), Node.ADD_NEW_FUNCTION); addNewFunctionModels = modelRoot.getAddNewFunctionModel(add); assertEquals(2, addNewFunctionModels.length); // make sure we have been returned an instance of the add we put in the // composite function assertTrue(add == addNewFunctionModels[0].getParent()); assertTrue(add2 == addNewFunctionModels[1].getParent()); }
@Test public void testGetChildren_4() { CompositeFunction compositeFunction = new CompositeFunction(); Add add = new Add(); compositeFunction.addFunction(add); add.addFunction(new Gaussian()); FunctionModelRoot modelRoot = new FunctionModelRoot(compositeFunction, provider); assertTreeLooksLike( modelRoot, Node.ADD(Node.GAUSSIAN, Node.ADD_NEW_FUNCTION), Node.ADD_NEW_FUNCTION); }
@Test public void testGetModelElement_2() { CompositeFunction compositeFunction = new CompositeFunction(); Add add = new Add(); add.addFunction(new Gaussian()); compositeFunction.addFunction(add); FunctionModelRoot modelRoot = new FunctionModelRoot(compositeFunction, provider); assertTreeLooksLike( modelRoot, Node.ADD(Node.GAUSSIAN, Node.ADD_NEW_FUNCTION), Node.ADD_NEW_FUNCTION); FunctionModelElement[] modelElements = modelRoot.getModelElement(new Gaussian()); assertTreeLooksLike(modelElements, Node.GAUSSIAN); modelElements = modelRoot.getModelElement(add); assertTreeLooksLike(modelElements, Node.ADD(Node.GAUSSIAN, Node.ADD_NEW_FUNCTION)); }