Пример #1
0
 /** Test if setting a stamp expressions marks the correct nodes as dirty. */
 public void testStampExpression() {
   Node number1 = numberNode.newInstance(testLibrary, "number1");
   Node stamp1 = Node.ROOT_NODE.newInstance(testLibrary, "stamp1", Integer.class);
   stamp1.addPort("value");
   stamp1.getPort("value").connect(number1);
   // The code prepares upstream dependencies for stamping, processes them and negates the output.
   String stampCode =
       "def cook(self):\n"
           + "  context.put('my_a', 99)\n"
           + "  self.node.stampDirty()\n"
           + "  self.node.updateDependencies(context)\n"
           + "  return -self.value # Negate the output";
   stamp1.setValue("_code", new PythonCode(stampCode));
   Parameter pValue = number1.getParameter("value");
   // Set number1 to a regular value. This should not influence the stamp operation.
   pValue.set(12);
   stamp1.update();
   assertEquals(-12, stamp1.getOutputValue());
   // Set number1 to an expression. Since we're not using stamp, nothing strange should happen to
   // the output.
   pValue.setExpression("2 + 1");
   stamp1.update();
   assertEquals(-3, stamp1.getOutputValue());
   // Set number1 to an unknown stamp expression. The default value will be picked.
   pValue.setExpression("stamp(\"xxx\", 19)");
   stamp1.update();
   assertEquals(-19, stamp1.getOutputValue());
   // Set number1 to the my_a stamp expression. The expression will be picked up.
   pValue.setExpression("stamp(\"my_a\", 33)");
   stamp1.update();
   assertEquals(-99, stamp1.getOutputValue());
 }
Пример #2
0
 /** Test if parameters with expressions are inherited correctly. */
 public void testExpressionPropagation() {
   // Inheritance: A <- B
   Node nodeA = Node.ROOT_NODE.newInstance(testLibrary, "A");
   Parameter pF = nodeA.addParameter("f", Parameter.Type.INT, 0);
   String expr1 = "12 + 5";
   pF.setExpression(expr1);
   Node nodeB = nodeA.newInstance(testLibrary, "B");
   assertEquals(expr1, nodeB.getParameter("f").getExpression());
   // Changing the expression of A does not automatically change that of B.
   String expr2 = "4 * 2";
   pF.setExpression(expr2);
   assertEquals(expr1, nodeB.getParameter("f").getExpression());
   // Reverting to default does.
   nodeB.getParameter("f").revertToDefault();
   assertEquals(expr2, nodeB.getParameter("f").getExpression());
 }
Пример #3
0
 /**
  * Test the hasStampExpression on the node.
  *
  * <p>This method is used to determine if parameters/nodes should be marked as dirty when
  * re-evaluating upstream, which is what happens in the copy node.
  */
 public void testHasStampExpression() {
   Node n = Node.ROOT_NODE.newInstance(testLibrary, "test");
   Parameter pAlpha = n.addParameter("alpha", Parameter.Type.FLOAT);
   Parameter pBeta = n.addParameter("beta", Parameter.Type.FLOAT);
   assertFalse(n.hasStampExpression());
   // Set the parameters to expressions that do not use the stamp function.
   pAlpha.setExpression(" 12 + 5");
   pBeta.setExpression("random(1, 5, 10)");
   assertFalse(n.hasStampExpression());
   // Set one of the parameters to the stamp function.
   pBeta.setExpression("stamp(\"mybeta\", 42)");
   assertTrue(n.hasStampExpression());
   // Set the other parameter expression to a stamp function as well.
   pAlpha.setExpression("stamp(\"myalpha\", 0) * 5");
   assertTrue(n.hasStampExpression());
   // Clear out the expressions one by one.
   pAlpha.clearExpression();
   assertTrue(n.hasStampExpression());
   // Change the beta parameter to some other expression.
   pBeta.setExpression("85 - 6");
   assertFalse(n.hasStampExpression());
 }