Package org.jamesii.core.math.parsetree

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


    assertTrue(res2.getValue().compareTo(true) == 0);
  }

  @Override
  public void testClone() {
    Node cond = new ValueNode<>(true);
    Node then = new ValueNode<>(5);
    Node els = new ValueNode<>(7);
    IfThenElseNode ifN = new IfThenElseNode(cond, then, els);

    Node n2 = null;
    try {
      n2 = (Node) ifN.clone();
    } catch (CloneNotSupportedException e) {
      fail(e.getMessage());
    }
View Full Code Here


    // assertTrue (res.get(2) != resClone.get(2));

  }

  public void testGetters() {
    Node cond = new ValueNode<>(true);
    Node then = new ValueNode<>(5);
    Node els = new ValueNode<>(7);
    IfThenElseNode ifN = new IfThenElseNode(cond, then, els);
    assertEquals(ifN.getElseStmt(), els);
    assertEquals(ifN.getThenStmt(), then);
    assertEquals(ifN.getCondition(), cond);
  }
View Full Code Here

    assertEquals(ifN.getCondition(), cond);
  }

  @Override
  public void testGetChildren() {
    Node cond = new ValueNode<>(true);
    Node then = new ValueNode<>(5);
    Node els = new ValueNode<>(7);
    IfThenElseNode ifN = new IfThenElseNode(cond, then, els);
    List<INode> res = ifN.getChildren();
    assertTrue(res.size() == 3);
    assertTrue(res.get(0) == cond);
    assertTrue(res.get(1) == then);
View Full Code Here

    assertTrue(val.getValue().compareTo(50) == 0);
  }

  @Override
  public void testClone() {
    Node n = new ValueNode<>(5);
    AssignmentNode<String> an = new AssignmentNode<>("ID1", n);

    Node n2 = null;
    try {
      n2 = (Node) an.clone();
    } catch (CloneNotSupportedException e) {
      fail(e.getMessage());
    }
View Full Code Here

  }

  @Override
  public void testGetChildren() {
    Node n = new ValueNode<>(5);
    AssignmentNode<String> an = new AssignmentNode<>("ID1", n);
    assertTrue(an.getChildren().size() == 1);
    assertTrue(an.getChildren().get(0) == n);
  }
View Full Code Here

*/
public class TestLengthNode extends TestValueNodeAbstract<LengthNode, INode> {

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

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

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

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

    node =
        getInstance(new ListNode(toList(new MultNode(new ValueNode<>(2),
            new ValueNode<>(-2.)))));
    res = node.calc(null);
    assertTrue(res.getValue().compareTo(1) == 0);

    node =
        getInstance(new ListNode(toList(new MultNode(new ValueNode<>(2),
            new ValueNode<>(-2.)), new MultNode(new ValueNode<>(2),
            new ValueNode<>(-3.)))));
    res = node.calc(null);
    assertTrue(res.getValue().compareTo(2) == 0);
  }
View Full Code Here

    caseTerms.add(new Pair<Comparable<?>, INode>(2, new ValueNode<>(3)));
    caseTerms.add(new Pair<Comparable<?>, INode>(1, new AddNode(
        new ValueNode<>(3), new ValueNode<>(3))));
    CaseNode cn = new CaseNode(caseStmt, caseTerms);

    Node n2 = null;
    try {
      n2 = (Node) cn.clone();
    } catch (CloneNotSupportedException e) {
      fail(e.getMessage());
    }
View Full Code Here

  @Override
  public void testClone() {
    ValueNode<Integer> a = new ValueNode<>(2);
    ValueNode<Integer> b = new ValueNode<>(4);
    Node n1 = getInstance(a, b);
    Node n2 = null;
    try {
      n2 = (Node) n1.clone();
    } catch (CloneNotSupportedException e) {
      fail(e.getMessage());
    }
View Full Code Here

public class TestListNode extends TestValueNodeAbstract<ListNode, List<INode>> {

  @SuppressWarnings("unchecked")
  @Override
  public void testCalc() {
    Node node = getInstance(getA(0));
    ListNode res = node.calc(null);
    List<INode> resList = res.getValue();
    assertTrue(((ValueNode<Integer>) resList.get(0)).getValue().compareTo(1) == 0);

    node = getInstance(getA(1));
    res = node.calc(null);
    resList = res.getValue();
    assertTrue(((ValueNode<Integer>) resList.get(0)).getValue().compareTo(-1) == 0);

    node = getInstance(getA(2));
    res = node.calc(null);
    resList = res.getValue();
    assertTrue(((ValueNode<Integer>) resList.get(0)).getValue().compareTo(0) == 0);

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

    node = getInstance(getA(4));
    res2 = node.calc(null);
    resList = res2.getValue();
    assertTrue(((ValueNode<Double>) resList.get(0)).getValue().compareTo(-1.) == 0);

    node = getInstance(getA(5));
    res2 = node.calc(null);
    resList = res2.getValue();
    assertTrue(((ValueNode<Double>) resList.get(0)).getValue().compareTo(0.) == 0);

    node =
        getInstance(toList(new MultNode(new ValueNode<>(2),
            new ValueNode<>(-2.))));
    res2 = node.calc(null);
    resList = res2.getValue();
    assertTrue(((ValueNode<Double>) resList.get(0)).getValue().compareTo(-4.) == 0);

    node =
        getInstance(toList(new MultNode(new ValueNode<>(2),
            new ValueNode<>(-2.)), new MultNode(new ValueNode<>(2),
            new ValueNode<>(-3.))));
    res2 = node.calc(null);
    resList = res2.getValue();
    assertTrue(((ValueNode<Double>) resList.get(0)).getValue().compareTo(-4.) == 0);
    assertTrue(((ValueNode<Double>) resList.get(1)).getValue().compareTo(-6.) == 0);
  }
View Full Code Here

*/
public class TestHeadNode extends TestValueNodeAbstract<HeadNode, INode> {

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

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

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

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

    node =
        getInstance(new ListNode(toList(new MultNode(new ValueNode<>(2),
            new ValueNode<>(-2.)))));
    res2 = node.calc(null);
    assertTrue(res2.getValue().compareTo(-4.) == 0);

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

TOP

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

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.