Class Test

  • All Implemented Interfaces:
    java.lang.Cloneable, Actor, Executable, FiringsRecordable, Initializable, TypedActor, Changeable, Debuggable, DebugListener, Derivable, Instantiable, ModelErrorHandler, MoMLExportable, Moveable, Nameable

    public class Test
    extends NonStrictTest

    This actor compares the inputs against the value specified by the correctValues parameter. That parameter is an ArrayToken, where each element of the array should have the same type as the input. The length of this array is the number of iterations of this actor that are tested. Subsequent iterations always succeed, so the actor can be used as a "power-up" test for a model, checking the first few iterations against some known results.

    The input is a multiport. If there is more than one channel connected to it, then each element of correctValues must itself be an ArrayToken, with length matching the number of channels. Suppose for example that the width of the input is one, and the first three inputs should be 1, 2, and 3. Then you can set correctValues to

     {1, 2, 3}
     

    Suppose instead that the input has width two, and the correct values in the first iteration are 1 on the first channel and 2 on the second. Then on the second iteration, the correct values are 3 on the first channel and 4 on the second. Then you can set correctValues to

     {{1, 2}, {3, 4}}
     

    With this setting, no tests are performed after the first two iterations of this actor.

    The input values are checked in the fire() method, which checks to make sure that each input channel has a token. If an input value is missing or differs from what it should be, then fire() throws an exception. Thus, the test passes if no exception is thrown. If you need to check the input value in postfire() (say, after a fixed-point iteration has converged), then use NonStrictTest.

    If the input is a DoubleToken or ComplexToken, then the comparison passes if the value is close to what it should be, within the specified tolerance (which defaults to 10-9. The input data type is undeclared, so it can resolve to anything.

    On each firing, this actor produces the output false until it reaches the end of the correctValues array, at which point it outputs true. This can be fed, for example, to an instance of the Stop actor to stop the test upon successfully matching the test data. In training mode, the output is always false.

    Since:
    Ptolemy II 1.0
    Version:
    $Id$
    Author:
    Edward A. Lee, Christopher Hylands, Jim Armstrong
    See Also:
    NonStrictTest
    Pt.AcceptedRating:
    Yellow (cxh)
    Pt.ProposedRating:
    Yellow (eal)
    • Field Detail

      • output

        public TypedIOPort output
        Boolean output that is false as long as there is data to compare against the input, but becomes true on the first firing after such data has been exhausted.
    • Method Detail

      • fire

        public void fire()
                  throws IllegalActionException
        Read one token from each input channel and compare against the value specified in correctValues. If the value does not match, then throw an exception. If the value matches, then output false if additional inputs are expected (to indicate that the test is not complete yet), and output true if this is the last expected input.

        If the iteration count is larger than the length of correctValues, then output true and return, indicating that the test is complete, i.e. that all values in correctValues have been matched.

        If the requireOrderedValues parameter is false, then the input can match any as yet unmatched value in correctValues.

        Specified by:
        fire in interface Executable
        Overrides:
        fire in class NonStrictTest
        Throws:
        IllegalActionException - If an input is missing, or if its value does not match the required value.
        See Also:
        NonStrictTest._firedOnce
      • postfire

        public boolean postfire()
        Override the base class to do nothing and return true.
        Specified by:
        postfire in interface Executable
        Overrides:
        postfire in class NonStrictTest
        Returns:
        True.