Ejemplo n.º 1
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));
  }
Ejemplo n.º 2
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);
  }
Ejemplo n.º 3
0
 protected Node[] getTreeLooksLike(FunctionModelRoot modelRoot) {
   List<Node> children = new ArrayList<>();
   for (FunctionModelElement functionModelElement : modelRoot.getChildren()) {
     children.add(getTreeLooksLike(functionModelElement));
   }
   return children.toArray(new Node[children.size()]);
 }
Ejemplo n.º 4
0
  @Test
  public void testSetFunctionOutOfOrder() {
    // Test that we can set the second function of a subtract
    CompositeFunction actual = new CompositeFunction();
    FunctionModelRoot modelRoot = new FunctionModelRoot(actual, provider);
    Subtract subtract = new Subtract();
    modelRoot.addFunction(subtract);
    SetFunctionModel[] setFunctionModel = modelRoot.getSetFunctionModel(subtract, 1);
    assertEquals(1, setFunctionModel.length);

    // If the ABinaryOperator's setFunction were to disallow setting index 1 before 0
    // then this would probably raise an exception
    setFunctionModel[0].setEditingValue("Gaussian");

    // If ABinaryOperator's setFunction put the function in the wrong place this would fail
    assertTreeLooksLike(
        modelRoot, Node.SUBTACT(Node.SET_FUNCTION, Node.GAUSSIAN), Node.ADD_NEW_FUNCTION);
  }
Ejemplo n.º 5
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);
  }
Ejemplo n.º 6
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());
  }
Ejemplo n.º 7
0
 private FunctionModelRoot createMockModelRoot() {
   FunctionModelRoot modelRoot = mock(FunctionModelRoot.class);
   when(modelRoot.getParameterModel(any(IParameter.class), any(Boolean.class)))
       .thenReturn(new ParameterModel[0]);
   return modelRoot;
 }