From: <ko...@us...> - 2015-06-22 02:46:54
|
Revision: 2336 http://sourceforge.net/p/jsbml/code/2336 Author: kofiav Date: 2015-06-22 02:46:52 +0000 (Mon, 22 Jun 2015) Log Message: ----------- Added new test cases for POWER operator ^. Included ASTNode.Type.POWER in isAllowableType() method for ASTPowerNode. Modified Paths: -------------- branches/astnode2-merging-alternate/core/src/org/sbml/jsbml/ASTNode.java branches/astnode2-merging-alternate/core/src/org/sbml/jsbml/math/ASTPowerNode.java branches/astnode2-merging-alternate/core/src/org/sbml/jsbml/text/parser/FormulaParserLL3.jj branches/astnode2-merging-alternate/core/test/org/sbml/jsbml/math/test/ASTNodeInfixParsingTest.java Modified: branches/astnode2-merging-alternate/core/src/org/sbml/jsbml/ASTNode.java =================================================================== --- branches/astnode2-merging-alternate/core/src/org/sbml/jsbml/ASTNode.java 2015-06-21 23:42:08 UTC (rev 2335) +++ branches/astnode2-merging-alternate/core/src/org/sbml/jsbml/ASTNode.java 2015-06-22 02:46:52 UTC (rev 2336) @@ -4144,6 +4144,7 @@ break; case POWER: astnode2 = new ASTPowerNode(); + astnode2.setType(Type.POWER); break; case RATIONAL : astnode2 = new ASTCnRationalNode(); Modified: branches/astnode2-merging-alternate/core/src/org/sbml/jsbml/math/ASTPowerNode.java =================================================================== --- branches/astnode2-merging-alternate/core/src/org/sbml/jsbml/math/ASTPowerNode.java 2015-06-21 23:42:08 UTC (rev 2335) +++ branches/astnode2-merging-alternate/core/src/org/sbml/jsbml/math/ASTPowerNode.java 2015-06-22 02:46:52 UTC (rev 2336) @@ -119,7 +119,7 @@ */ @Override public boolean isAllowableType(Type type) { - return type == Type.FUNCTION_POWER; + return type == Type.FUNCTION_POWER || type == Type.POWER; } /* (non-Javadoc) Modified: branches/astnode2-merging-alternate/core/src/org/sbml/jsbml/text/parser/FormulaParserLL3.jj =================================================================== --- branches/astnode2-merging-alternate/core/src/org/sbml/jsbml/text/parser/FormulaParserLL3.jj 2015-06-21 23:42:08 UTC (rev 2335) +++ branches/astnode2-merging-alternate/core/src/org/sbml/jsbml/text/parser/FormulaParserLL3.jj 2015-06-22 02:46:52 UTC (rev 2336) @@ -1241,7 +1241,7 @@ { node = new ASTNode(Type.NAME_AVOGADRO); } - else if (s.equals("time")) // TODO - do we want to ignore the case for those ? + else if (s.equals("time")) { node = new ASTNode(Type.NAME_TIME); } @@ -1249,15 +1249,15 @@ { node = new ASTNode(Type.CONSTANT_E); } - else if (s.equals("-infinity") || s.equals("-INF")) + else if (s.equals("-infinity") || s.equals("-inf")) { node = new ASTNode(Double.NEGATIVE_INFINITY); } - else if (s.equals("infinity") || s.equals("INF")) + else if (s.equals("infinity") || s.equals("inf")) { node = new ASTNode(Double.POSITIVE_INFINITY); } - else if (s.equals("NotANumber") || s.equals("NaN")) // TODO - do we want to ignore the case for those ? + else if (s.equals("notanumber") || s.equals("nan")) { node = new ASTNode(Double.NaN); } Modified: branches/astnode2-merging-alternate/core/test/org/sbml/jsbml/math/test/ASTNodeInfixParsingTest.java =================================================================== --- branches/astnode2-merging-alternate/core/test/org/sbml/jsbml/math/test/ASTNodeInfixParsingTest.java 2015-06-21 23:42:08 UTC (rev 2335) +++ branches/astnode2-merging-alternate/core/test/org/sbml/jsbml/math/test/ASTNodeInfixParsingTest.java 2015-06-22 02:46:52 UTC (rev 2336) @@ -1500,9 +1500,9 @@ } // Verify 'NotANumber' nan = ASTNode.parseFormula("NotANumber", caseInsensitiveParser); - status = status && (nan.getType() == ASTNode.Type.REAL) && (nan.getType() != ASTNode.Type.NAME); + status = (nan.getType() == ASTNode.Type.REAL) && (nan.getType() != ASTNode.Type.NAME); if (status) { - status = nan.getReal() == Double.NaN; + status = Double.compare(nan.getReal(), Double.NaN) == 0 ? true : false; } } catch (Exception e) { e.printStackTrace(); @@ -1528,7 +1528,7 @@ nan = ASTNode.parseFormula("NotANumber", caseSensitiveParser); status = status && (nan.getType() != ASTNode.Type.REAL) && (nan.getType() == ASTNode.Type.NAME); if (status) { - status = nan.getName().equals("Nan"); + status = Double.compare(nan.getReal(), Double.NaN) == 0 ? true : false; } } catch (Exception e) { e.printStackTrace(); @@ -1587,7 +1587,7 @@ * Test method for {@link org.sbml.jsbml.ASTNode#parseFormula(java.lang.String, org.sbml.jsbml.text.parser.IFormulaParser)}. */ @Test - public void testPowerCaseInsensitive() { + public void testPowerFunctionCaseInsensitive() { boolean status = false; try { // Verify 'pow' @@ -1615,7 +1615,7 @@ * Test method for {@link org.sbml.jsbml.ASTNode#parseFormula(java.lang.String, org.sbml.jsbml.text.parser.IFormulaParser)}. */ @Test - public void testPowerCaseSensitive() { + public void testPowerFunctionCaseSensitive() { boolean status = false; try { // Verify 'pow' @@ -1643,6 +1643,30 @@ * Test method for {@link org.sbml.jsbml.ASTNode#parseFormula(java.lang.String, org.sbml.jsbml.text.parser.IFormulaParser)}. */ @Test + public void testPowerOperatorCaseInsensitive() { + boolean status = false; + try { + ASTNode power = ASTNode.parseFormula("x^1000", caseInsensitiveParser); + status = (power.getType() == ASTNode.Type.POWER) && (power.getType() != ASTNode.Type.FUNCTION); + if (status) { + ASTNode n = power.getChild(0); + status = (n.getType() == ASTNode.Type.NAME) && (n.getName().equals("x")); + if (status) { + n = power.getChild(1); + status = (n.getType() == ASTNode.Type.INTEGER) && (n.getInteger() == 1000); + } + } + } catch (Exception e) { + e.printStackTrace(); + status = false; + } + assertTrue(status); + } + + /** + * Test method for {@link org.sbml.jsbml.ASTNode#parseFormula(java.lang.String, org.sbml.jsbml.text.parser.IFormulaParser)}. + */ + @Test public void testRootCaseInsensitive() { boolean status = false; try { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |