public void testParameters() { Node n = Node.ROOT_NODE; assertNull(n.getParameter("p1")); assertTrue(n.hasParameter("_code")); assertNotNull(n.getParameter("_code")); assertNull(n.getParameter("x")); }
public void testBaseNode() { Node baseNode = Node.ROOT_NODE; Parameter pCode = baseNode.getParameter("_code"); Parameter pHandle = baseNode.getParameter("_handle"); assertEquals("_code", pCode.getName()); assertEquals(Parameter.Type.CODE, pCode.getType()); assertEquals("_handle", pHandle.getName()); assertEquals(Parameter.Type.CODE, pHandle.getType()); baseNode.update(); assertNull(baseNode.getOutputValue()); }
/** 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()); }
/** 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()); }
/** Test propagation behaviour for parameters. */ public void testParameterPropagation() { // Inheritance: A <- B Node nodeA = Node.ROOT_NODE.newInstance(testLibrary, "A"); nodeA.addParameter("f", Parameter.Type.FLOAT, 1F); Node nodeB = nodeA.newInstance(testLibrary, "B"); // The parameters of A and B are not the same. assertNotSame(nodeA.getParameter("f"), nodeB.getParameter("f")); nodeA.setValue("f", 10F); // The value for the B parameter doesn't automatically change when A was changed. assertEquals(10F, nodeA.asFloat("f")); assertEquals(1F, nodeB.asFloat("f")); // Setting the value of B does not affect the value of A. nodeB.getParameter("f").setValue(55F); assertEquals(10F, nodeA.asFloat("f")); assertEquals(55F, nodeB.asFloat("f")); // Reverting to the default value will force B to load the new parameter value // from the prototype. nodeB.getParameter("f").revertToDefault(); assertEquals(10F, nodeB.asFloat("f")); }
public void testDirty() { Node n = numberNode.newInstance(testLibrary, "number1"); assertTrue(n.isDirty()); n.update(); assertFalse(n.isDirty()); n.setValue("value", 12); assertTrue(n.isDirty()); n.update(); assertFalse(n.isDirty()); n.getParameter("value").set(13); assertTrue(n.isDirty()); n.update(); assertFalse(n.isDirty()); }