@Test public void testGetChildren_3() { CompositeFunction compositeFunction = new CompositeFunction(); compositeFunction.addFunction(new Gaussian()); compositeFunction.addFunction(new Fermi()); FunctionModelRoot modelRoot = new FunctionModelRoot(compositeFunction, provider); assertTreeLooksLike(modelRoot, Node.GAUSSIAN, Node.FERMI, Node.ADD_NEW_FUNCTION); }
@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 testModifyListenerFires() { CompositeFunction compositeFunction = new CompositeFunction(); Gaussian gaussian = new Gaussian(); compositeFunction.addFunction(gaussian); FunctionModelRoot modelRoot = new FunctionModelRoot(compositeFunction, provider); IModelModifiedListener listener = mock(IModelModifiedListener.class); modelRoot.addModelModifiedListener(listener); ParameterModel[] parameterModel = modelRoot.getParameterModel(gaussian, 0); assertEquals(1, parameterModel.length); parameterModel[0].setParameterValue("456.7"); verify(listener, times(1)).parameterModified(any(IParameterModifiedEvent.class)); parameterModel[0].setParameterLowerLimit("123.4"); verify(listener, times(2)).parameterModified(any(IParameterModifiedEvent.class)); parameterModel[0].setParameterUpperLimit("890.1"); verify(listener, times(3)).parameterModified(any(IParameterModifiedEvent.class)); parameterModel[0].setParameterFixed(true); verify(listener, times(4)).parameterModified(any(IParameterModifiedEvent.class)); // check (demonstrate!) that modifying the underlying IParameter does // not fire event (i.e. if you bypass the model, you don't get events) parameterModel[0].getParameter().setValue(123.456); verify(listener, times(4)).parameterModified(any(IParameterModifiedEvent.class)); }
@Test public void testGetModelElement_1() { CompositeFunction compositeFunction = new CompositeFunction(); compositeFunction.addFunction(new Gaussian()); FunctionModelRoot modelRoot = new FunctionModelRoot(compositeFunction, provider); assertTreeLooksLike(modelRoot, Node.GAUSSIAN, Node.ADD_NEW_FUNCTION); FunctionModelElement[] modelElements = modelRoot.getModelElement(new Gaussian()); assertTreeLooksLike(modelElements, Node.GAUSSIAN); }
@Test public void testGetChildren_5() { CompositeFunction compositeFunction = new CompositeFunction(); Subtract sub = new Subtract(); compositeFunction.addFunction(sub); sub.addFunction(new Gaussian()); FunctionModelRoot modelRoot = new FunctionModelRoot(compositeFunction, provider); assertTreeLooksLike( modelRoot, Node.SUBTACT(Node.GAUSSIAN, Node.SET_FUNCTION), Node.ADD_NEW_FUNCTION); }
@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 testGetSetFunctionModel() { CompositeFunction compositeFunction = new CompositeFunction(); Subtract sub = new Subtract(); sub.addFunction(new Gaussian()); compositeFunction.addFunction(sub); FunctionModelRoot modelRoot = new FunctionModelRoot(compositeFunction, provider); assertTreeLooksLike( modelRoot, Node.SUBTACT(Node.GAUSSIAN, Node.SET_FUNCTION), Node.ADD_NEW_FUNCTION); SetFunctionModel[] setFunctionModels = modelRoot.getSetFunctionModel(sub, 1); assertEquals(1, setFunctionModels.length); assertTrue(sub == setFunctionModels[0].getParent()); assertEquals(1, setFunctionModels[0].getFunctionIndex()); assertEquals(0, modelRoot.getSetFunctionModel(sub, 0).length); assertEquals(0, modelRoot.getSetFunctionModel(new Subtract(), 0).length); assertEquals(0, modelRoot.getSetFunctionModel(new Subtract(), 1).length); assertEquals(0, modelRoot.getSetFunctionModel(new Add(), 0).length); }
/** * Removes a function from the list * * @param index The position in the vector to be removed */ public void removeFunction(int index) { List<IParameter> plist = new ArrayList<IParameter>(); List<AFunction> flist = new ArrayList<AFunction>(); NavigableMap<Integer, AFunction> fmap = new TreeMap<Integer, AFunction>(); int nfuncs = functionList.size(); if (index > nfuncs) { logger.error("Index exceed bounds"); throw new IndexOutOfBoundsException("Index exceed bounds"); } for (int n = 0; n < nfuncs; n++) { if (n != index) { AFunction f = functionList.get(n); addFunction(plist, flist, fmap, f); } } parameterList = plist; functionList = flist; functionMap = fmap; }
/** * Adds a new function of the type AFunction to the array * * @param function */ public void addFunction(AFunction function) { addFunction(parameterList, functionList, functionMap, function); }