Esempio n. 1
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);
  }
Esempio n. 2
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);
  }