Package org.jamesii.core.math.parsetree

Examples of org.jamesii.core.math.parsetree.INode


  @Override
  public <N extends INode> N calc(IEnvironment<?> cEnv) {

    ValueNode val = caseStmt.calc(cEnv);

    INode defaultExpr = null;

    for (Pair<? extends Comparable, INode> p : caseTerms) {
      // default case
      if (p.getFirstValue() == null) {
        defaultExpr = p.getSecondValue();
        // continue with checking all other cases
        continue;
      }

      // any other than default case
      if (p.getFirstValue().compareTo(val.getValue()) == 0) {
        return (N) p.getSecondValue().calc(cEnv);
      }
    }

    if (defaultExpr != null) {
      return (N) defaultExpr.calc(cEnv);
    }

    return null;
  }
View Full Code Here


  }

  @SuppressWarnings("unchecked")
  @Override
  public <N extends INode> N calc(IEnvironment<?> cEnv) {
    INode v = value.calc(cEnv);
    ((IEnvironment<Serializable>) cEnv).setValue(ident, v);
    return (N) new Identifier<>(ident, v);
  }
View Full Code Here

  /** The Constant serialVersionUID. */
  private static final long serialVersionUID = -7080751306938363931L;

  @Override
  public IVariableModifier<?> create(ParameterBlock parameter, Context context) {
    INode mathExpression =
        ParameterBlocks.getSubBlockValue(parameter, EXPRESSION);
    return createModifier(mathExpression);
  }
View Full Code Here

*/
public class TestSqrtNode extends TestValueNodeAbstract<SqrtNode, INode> {

  @Override
  public void testCalc() {
    INode node = getInstance(getA(0));
    ValueNode<Double> res = node.calc(null);
    assertTrue(res.getValue().compareTo(Math.sqrt(1)) == 0);

    node = getInstance(getA(1));
    res = node.calc(null);
    assertTrue(res.getValue().compareTo(Math.sqrt(36)) == 0);

    node = getInstance(getA(2));
    res = node.calc(null);
    assertTrue(res.getValue().compareTo(Math.sqrt(0)) == 0);

    node = getInstance(getA(3));
    ValueNode<Double> res2 = node.calc(null);
    assertTrue(res2.getValue().compareTo(Math.sqrt(1.)) == 0);

    node = getInstance(getA(4));
    res2 = node.calc(null);
    assertTrue(res2.getValue().compareTo(Math.sqrt(9.)) == 0);

    node = getInstance(getA(5));
    res2 = node.calc(null);
    assertTrue(res2.getValue().compareTo(Math.sqrt(0.)) == 0);

    node = getInstance((new MultNode(new ValueNode<>(2), new ValueNode<>(2.))));
    res2 = node.calc(null);
    assertTrue(res2.getValue().compareTo(Math.sqrt(4.)) == 0);
  }
View Full Code Here

*/
public class TestCeilingNode extends TestValueNodeAbstract<CeilingNode, INode> {

  @Override
  public void testCalc() {
    INode node = getInstance(getA(0));
    ValueNode<Double> res = node.calc(null);
    assertTrue(res.getValue().compareTo(Math.ceil(1)) == 0);

    node = getInstance(getA(1));
    res = node.calc(null);
    assertTrue(res.getValue().compareTo(Math.ceil(-1)) == 0);

    node = getInstance(getA(2));
    res = node.calc(null);
    assertTrue(res.getValue().compareTo(Math.ceil(0)) == 0);

    node = getInstance(getA(3));
    ValueNode<Double> res2 = node.calc(null);
    assertTrue(res2.getValue().compareTo(Math.ceil(1.)) == 0);

    node = getInstance(getA(4));
    res2 = node.calc(null);
    assertTrue(res2.getValue().compareTo(Math.ceil(-1.)) == 0);

    node = getInstance(getA(5));
    res2 = node.calc(null);
    assertTrue(res2.getValue().compareTo(Math.ceil(0.)) == 0);

    node =
        getInstance((new MultNode(new ValueNode<>(2), new ValueNode<>(-2.))));
    res2 = node.calc(null);
    assertTrue(res2.getValue().compareTo(Math.ceil(-4.)) == 0);
  }
View Full Code Here

*/
public class TestSinNode extends TestValueNodeAbstract<SinNode, INode> {

  @Override
  public void testCalc() {
    INode node = getInstance(getA(0));
    ValueNode<Double> res = node.calc(null);
    assertTrue(res.getValue().compareTo(Math.sin(1)) == 0);

    node = getInstance(getA(1));
    res = node.calc(null);
    assertTrue(res.getValue().compareTo(Math.sin(-1)) == 0);

    node = getInstance(getA(2));
    res = node.calc(null);
    assertTrue(res.getValue().compareTo(Math.sin(0)) == 0);

    node = getInstance(getA(3));
    ValueNode<Double> res2 = node.calc(null);
    assertTrue(res2.getValue().compareTo(Math.sin(1.)) == 0);

    node = getInstance(getA(4));
    res2 = node.calc(null);
    assertTrue(res2.getValue().compareTo(Math.sin(-1.)) == 0);

    node = getInstance(getA(5));
    res2 = node.calc(null);
    assertTrue(res2.getValue().compareTo(Math.sin(0.)) == 0);

    node =
        getInstance((new MultNode(new ValueNode<>(2), new ValueNode<>(-2.))));
    res2 = node.calc(null);
    assertTrue(res2.getValue().compareTo(Math.sin(-4.)) == 0);
  }
View Full Code Here

*/
public class TestTanNode extends TestValueNodeAbstract<TanNode, INode> {

  @Override
  public void testCalc() {
    INode node = getInstance(getA(0));
    ValueNode<Double> res = node.calc(null);
    assertTrue(res.getValue().compareTo(Math.tan(1)) == 0);

    node = getInstance(getA(1));
    res = node.calc(null);
    assertTrue(res.getValue().compareTo(Math.tan(-1)) == 0);

    node = getInstance(getA(2));
    res = node.calc(null);
    assertTrue(res.getValue().compareTo(Math.tan(0)) == 0);

    node = getInstance(getA(3));
    ValueNode<Double> res2 = node.calc(null);
    assertTrue(res2.getValue().compareTo(Math.tan(1.)) == 0);

    node = getInstance(getA(4));
    res2 = node.calc(null);
    assertTrue(res2.getValue().compareTo(Math.tan(-1.)) == 0);

    node = getInstance(getA(5));
    res2 = node.calc(null);
    assertTrue(res2.getValue().compareTo(Math.tan(0.)) == 0);

    node =
        getInstance((new MultNode(new ValueNode<>(2), new ValueNode<>(-2.))));
    res2 = node.calc(null);
    assertTrue(res2.getValue().compareTo(Math.tan(-4.)) == 0);
  }
View Full Code Here

*/
public class TestArcTanNode extends TestValueNodeAbstract<ArcTanNode, INode> {

  @Override
  public void testCalc() {
    INode node = getInstance(getA(0));
    ValueNode<Double> res = node.calc(null);
    assertTrue(res.getValue().compareTo(Math.atan(1)) == 0);

    node = getInstance(getA(1));
    res = node.calc(null);
    assertTrue(res.getValue().compareTo(Math.atan(-1)) == 0);

    node = getInstance(getA(2));
    res = node.calc(null);
    assertTrue(res.getValue().compareTo(Math.atan(0)) == 0);

    node = getInstance(getA(3));
    ValueNode<Double> res2 = node.calc(null);
    assertTrue(res2.getValue().compareTo(Math.atan(1.)) == 0);

    node = getInstance(getA(4));
    res2 = node.calc(null);
    assertTrue(res2.getValue().compareTo(Math.atan(-1.)) == 0);

    node = getInstance(getA(5));
    res2 = node.calc(null);
    assertTrue(res2.getValue().compareTo(Math.atan(0.)) == 0);

    node =
        getInstance((new MultNode(new ValueNode<>(2), new ValueNode<>(-2.))));
    res2 = node.calc(null);
    assertTrue(res2.getValue().compareTo(Math.atan(-4.)) == 0);
  }
View Full Code Here

*/
public class TestArcSinNode extends TestValueNodeAbstract<ArcSinNode, INode> {

  @Override
  public void testCalc() {
    INode node = getInstance(getA(0));
    ValueNode<Double> res = node.calc(null);
    assertTrue(res.getValue().compareTo(Math.asin(1)) == 0);

    node = getInstance(getA(1));
    res = node.calc(null);
    assertTrue(res.getValue().compareTo(Math.asin(-1)) == 0);

    node = getInstance(getA(2));
    res = node.calc(null);
    assertTrue(res.getValue().compareTo(Math.asin(0)) == 0);

    node = getInstance(getA(3));
    ValueNode<Double> res2 = node.calc(null);
    assertTrue(res2.getValue().compareTo(Math.asin(1.)) == 0);

    node = getInstance(getA(4));
    res2 = node.calc(null);
    assertTrue(res2.getValue().compareTo(Math.asin(-1.)) == 0);

    node = getInstance(getA(5));
    res2 = node.calc(null);
    assertTrue(res2.getValue().compareTo(Math.asin(0.)) == 0);

    node =
        getInstance((new MultNode(new ValueNode<>(2), new ValueNode<>(-2.))));
    res2 = node.calc(null);
    assertTrue(res2.getValue().compareTo(Math.asin(-4.)) == 0);
  }
View Full Code Here

*/
public class TestCoshNode extends TestValueNodeAbstract<CoshNode, INode> {

  @Override
  public void testCalc() {
    INode node = getInstance(getA(0));
    ValueNode<Double> res = node.calc(null);
    assertTrue(res.getValue().compareTo(Math.cosh(1)) == 0);

    node = getInstance(getA(1));
    res = node.calc(null);
    assertTrue(res.getValue().compareTo(Math.cosh(-1)) == 0);

    node = getInstance(getA(2));
    res = node.calc(null);
    assertTrue(res.getValue().compareTo(Math.cosh(0)) == 0);

    node = getInstance(getA(3));
    ValueNode<Double> res2 = node.calc(null);
    assertTrue(res2.getValue().compareTo(Math.cosh(1.)) == 0);

    node = getInstance(getA(4));
    res2 = node.calc(null);
    assertTrue(res2.getValue().compareTo(Math.cosh(-1.)) == 0);

    node = getInstance(getA(5));
    res2 = node.calc(null);
    assertTrue(res2.getValue().compareTo(Math.cosh(0.)) == 0);

    node =
        getInstance((new MultNode(new ValueNode<>(2), new ValueNode<>(-2.))));
    res2 = node.calc(null);
    assertTrue(res2.getValue().compareTo(Math.cosh(-4.)) == 0);
  }
View Full Code Here

TOP

Related Classes of org.jamesii.core.math.parsetree.INode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.