Esempio n. 1
0
 @Test
 public void testGetChildren_2() {
   CompositeFunction compositeFunction = new CompositeFunction();
   compositeFunction.addFunction(new Gaussian());
   FunctionModelRoot modelRoot = new FunctionModelRoot(compositeFunction, provider);
   assertTreeLooksLike(modelRoot, Node.GAUSSIAN, Node.ADD_NEW_FUNCTION);
 }
Esempio n. 2
0
  @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));
  }
Esempio n. 3
0
  @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);
  }
Esempio n. 4
0
 @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);
 }
Esempio n. 5
0
  @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());
  }
Esempio n. 6
0
  @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);
  }
  private void populateDataBasedFunctions(
      final Map<String, Serializable> data, IFunction function) {

    if (function instanceof CompositeFunction) {
      CompositeFunction compositeFunction = (CompositeFunction) function;
      for (IFunction func : compositeFunction.getFunctions()) {
        populateDataBasedFunctions(data, func);
      }
    }

    if (function instanceof IDataBasedFunction) {
      IDataBasedFunction dbFunction = (IDataBasedFunction) function;

      String sdName = seedDataName.getExpression();
      String sdAxis = seedAxisName.getExpression();
      Dataset seedDataset = DatasetFactory.createFromObject(data.get(sdName)).clone();
      Dataset seedAxisDataset = DatasetFactory.createFromObject(data.get(sdAxis)).clone();
      dbFunction.setData(seedAxisDataset, seedDataset);
    }
  }