Package com.singularsys.jep.walkers

# Class TestingVisitor

java.lang.Object
com.singularsys.jep.walkers.TestingVisitor

All Implemented Interfaces:
  `GenericVisitor<Boolean,Predicate<Node>,JepException>`

public class TestingVisitor extends Object implements GenericVisitor<Boolean,Predicate<Node>,JepException>
A visitor than can test all nodes in a tree against a set of predicates. First a visitor is constructed and then the `test(Node)` method is called to test an expression.

This visitor checks all operators and functions have assigned pfmc's.

    TestingVisitor tv = new TestingVisitor(
         n -> n instanceof ASTOpNode
              ? n.getPFMC()!=null
              : true,
         n -> n instanceof ASTFunNode
              ? n.getPFMC()!=null
              : true
           );

This visitor checks all literal constants are Doubles

    TestingVisitor tv = new TestingVisitor(
         n -> n instanceof ASTConstant
              ? n.getValue() instanceof Double
              : true);

This visitor checks the assumption that PFMC of an operator node matches the PFMC of the operator.

    TestingVisitor tv = new TestingVisitor(
        n -> n instanceof ASTOpNode
             ? n.getOperator().getPFMC() == n.getPFMC()
             : true);

Since:
  Jep 4.1

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `TestingVisitor(Predicate<Node>... preds)`
  Constructor with a set of Predicate to use in test

- ## Method Summary

  Modifier and Type
  Method
  Description
  `JepException`
  `makeException(String s)`
  Create an Exception of the correct type.
  `boolean`
  `test(Node n)`
  Test using the set of Predicates given in the constructor
  `boolean`
  `test(Node n, Predicate<Node> pred)`
  Test using a supplied Predicate
  `Boolean`
  `visit(ASTConstant node, Predicate<Node> data)`
  Visit a constant node
  `Boolean`
  `visit(ASTFunNode node, Predicate<Node> data)`
  Visit a function node
  `Boolean`
  `visit(ASTOpNode node, Predicate<Node> data)`
  Visit an operator node
  `Boolean`
  `visit(ASTVarNode node, Predicate<Node> data)`
  Visit a variable node

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

  ### Methods inherited from interface com.singularsys.jep.GenericVisitor

  `makeException, visit, visitChildren`

- ## Constructor Details

  - ### TestingVisitor

    @SafeVarargs public TestingVisitor(Predicate<Node>... preds)
    Constructor with a set of Predicate to use in test
    Parameters:
      `preds` - zero or more Predicates

- ## Method Details

  - ### test

    public boolean test(Node n) throws JepException
    Test using the set of Predicates given in the constructor
    Parameters:
      `n` - root node to test
    Returns:
      true if all test pass for all nodes, false otherwise
    Throws:
      `JepException`

  - ### test

    public boolean test(Node n, Predicate<Node> pred) throws JepException
    Test using a supplied Predicate
    Parameters:
      `n` - root node to test
      `pred` - predicate to test
    Returns:
    Throws:
      `JepException`

  - ### visit

    public Boolean visit(ASTConstant node, Predicate<Node> data) throws JepException
    Description copied from interface: `GenericVisitor`
    Visit a constant node
    Specified by:
      `visit` in interface `GenericVisitor<Boolean,Predicate<Node>,JepException>`
    Parameters:
      `node` - current node
      `data` - context data
    Returns:
      the result of visiting the node
    Throws:
      `JepException`

  - ### visit

    public Boolean visit(ASTFunNode node, Predicate<Node> data) throws JepException
    Description copied from interface: `GenericVisitor`
    Visit a function node
    Specified by:
      `visit` in interface `GenericVisitor<Boolean,Predicate<Node>,JepException>`
    Parameters:
      `node` - current node
      `data` - context data
    Returns:
      the result of visiting the node
    Throws:
      `JepException`

  - ### visit

    public Boolean visit(ASTVarNode node, Predicate<Node> data) throws JepException
    Description copied from interface: `GenericVisitor`
    Visit a variable node
    Specified by:
      `visit` in interface `GenericVisitor<Boolean,Predicate<Node>,JepException>`
    Parameters:
      `node` - current node
      `data` - context data
    Returns:
      the result of visiting the node
    Throws:
      `JepException`

  - ### visit

    public Boolean visit(ASTOpNode node, Predicate<Node> data) throws JepException
    Description copied from interface: `GenericVisitor`
    Visit an operator node
    Specified by:
      `visit` in interface `GenericVisitor<Boolean,Predicate<Node>,JepException>`
    Parameters:
      `node` - current node
      `data` - context data
    Returns:
      the result of visiting the node
    Throws:
      `JepException`

  - ### makeException

    public JepException makeException(String s)
    Description copied from interface: `GenericVisitor`
    Create an Exception of the correct type. A typical implementation is

        @Override
        public JepException makeException(String message) {
         return new JepException(message);
        }

    Specified by:
      `makeException` in interface `GenericVisitor<Boolean,Predicate<Node>,JepException>`
    Parameters:
      `s` - error message
    Returns:
      an Exception