Author: ruschein
Date: 2011-03-30 15:48:27 -0700 (Wed, 30 Mar 2011)
New Revision: 24625
Modified:
core3/equations-impl/trunk/src/main/java/org/cytoscape/equations/internal/EquationParserImpl.java
core3/equations-impl/trunk/src/test/java/org/cytoscape/equations/internal/interpreter/InterpreterTest.java
Log:
Fixed a unary operator bug having to do with unary minus on integers being
incorrectly rejected.
Modified:
core3/equations-impl/trunk/src/main/java/org/cytoscape/equations/internal/EquationParserImpl.java
===================================================================
---
core3/equations-impl/trunk/src/main/java/org/cytoscape/equations/internal/EquationParserImpl.java
2011-03-30 22:46:51 UTC (rev 24624)
+++
core3/equations-impl/trunk/src/main/java/org/cytoscape/equations/internal/EquationParserImpl.java
2011-03-30 22:48:27 UTC (rev 24625)
@@ -39,6 +39,7 @@
import org.cytoscape.equations.EquationParser;
import org.cytoscape.equations.Function;
+import org.cytoscape.equations.FunctionUtil;
import org.cytoscape.equations.Node;
import org.cytoscape.equations.internal.builtins.*;
import org.cytoscape.equations.internal.parse_tree.*;
@@ -306,10 +307,15 @@
}
private Node handleUnaryOp(final int sourceLocation, final Token
operator, final Node operand) {
- if (operand.getType() == Boolean.class || operand.getType() ==
String.class)
+ final Class<?> operandType = operand.getType();
+ if (operandType == Boolean.class || operandType == String.class
+ || FunctionUtil.isSomeKindOfList(operandType))
throw new ArithmeticException(sourceLocation + ": can't
apply a unary " + operator.asString()
+ " a boolean, string or
list operand!");
- return new UnaryOpNode(sourceLocation, operator, operand);
+ if (operandType == Double.class)
+ return new UnaryOpNode(sourceLocation, operator,
operand);
+ else
+ return new UnaryOpNode(sourceLocation, operator, new
FConvNode(operand));
}
/**
Modified:
core3/equations-impl/trunk/src/test/java/org/cytoscape/equations/internal/interpreter/InterpreterTest.java
===================================================================
---
core3/equations-impl/trunk/src/test/java/org/cytoscape/equations/internal/interpreter/InterpreterTest.java
2011-03-30 22:46:51 UTC (rev 24624)
+++
core3/equations-impl/trunk/src/test/java/org/cytoscape/equations/internal/interpreter/InterpreterTest.java
2011-03-30 22:48:27 UTC (rev 24625)
@@ -91,6 +91,15 @@
assertEquals(new Double(12.0),
interpreter.execute(compiler.getEquation(), nameToDescriptorMap));
}
+ public void testUnaryPlusAndMinus2() throws Exception {
+ final Map<String, Class<?>> attribNameToTypeMap = new
HashMap<String, Class<?>>();
+ attribNameToTypeMap.put("attr1", Long.class);
+ assertTrue(compiler.compile("=-$attr1", attribNameToTypeMap));
+ final Map<String, IdentDescriptor> nameToDescriptorMap = new
HashMap<String, IdentDescriptor>();
+ nameToDescriptorMap.put("attr1", new IdentDescriptor(5L));
+ assertEquals(new Double(-5.0),
interpreter.execute(compiler.getEquation(), nameToDescriptorMap));
+ }
+
public void testFunctionCall() throws Exception {
final Map<String, Class<?>> attribNameToTypeMap = new
HashMap<String, Class<?>>();
assertTrue(compiler.compile("=42 + log(4 - 2)",
attribNameToTypeMap));
--
You received this message because you are subscribed to the Google Groups
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/cytoscape-cvs?hl=en.