ptolemy.actor.lib
Class Test

java.lang.Object
  extended byptolemy.kernel.util.NamedObj
      extended byptolemy.kernel.InstantiableNamedObj
          extended byptolemy.kernel.Entity
              extended byptolemy.kernel.ComponentEntity
                  extended byptolemy.actor.AtomicActor
                      extended byptolemy.actor.TypedAtomicActor
                          extended byptolemy.actor.lib.Sink
                              extended byptolemy.actor.lib.NonStrictTest
                                  extended byptolemy.actor.lib.Test
All Implemented Interfaces:
Actor, Changeable, java.lang.Cloneable, Debuggable, DebugListener, Derivable, Executable, Instantiable, ModelErrorHandler, MoMLExportable, Nameable, java.io.Serializable, TypedActor

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.

Since:
Ptolemy II 1.0
Version:
$Id: Test.java,v 1.45 2004/04/13 03:04:37 cxh Exp $
Author:
Edward A. Lee, Christopher Hylands, Jim Armstrong
See Also:
NonStrictTest, Serialized Form
Accepted Rating:
Yellow (cxh)
Proposed Rating:
Yellow (eal)

Nested Class Summary
 
Nested classes inherited from class ptolemy.kernel.Entity
Entity.ContainedObjectsIterator
 
Field Summary
 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.
 
Fields inherited from class ptolemy.actor.lib.NonStrictTest
_iteration, _numberOfInputTokensSeen, _tolerance, _trainingTokens, correctValues, tolerance, TRAINING_MODE_ERROR_MESSAGE, trainingMode
 
Fields inherited from class ptolemy.actor.lib.Sink
input
 
Fields inherited from class ptolemy.actor.AtomicActor
_stopRequested
 
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _elementName, _isPersistent, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
 
Fields inherited from interface ptolemy.actor.Executable
COMPLETED, NOT_READY, STOP_ITERATING
 
Constructor Summary
Test(CompositeEntity container, java.lang.String name)
          Construct an actor with an input multiport.
 
Method Summary
 void fire()
          Read one token from each input channel and compare against the value specified in correctValues.
 boolean postfire()
          Override the base class to do nothing and return true.
 
Methods inherited from class ptolemy.actor.lib.NonStrictTest
attributeChanged, initialize, isRunningNightlyBuild, wrapup
 
Methods inherited from class ptolemy.actor.TypedAtomicActor
_addPort, attributeTypeChanged, clone, newPort, typeConstraintList
 
Methods inherited from class ptolemy.actor.AtomicActor
_createReceivers, clone, connectionsChanged, getDirector, getExecutiveDirector, getFunctionDependency, getManager, inputPortList, iterate, newReceiver, outputPortList, prefire, preinitialize, pruneDependencies, removeDependency, setContainer, stop, stopFire, terminate
 
Methods inherited from class ptolemy.kernel.ComponentEntity
_adjustDeferrals, _checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, isAtomic, isOpaque, propagateExistence, setName
 
Methods inherited from class ptolemy.kernel.Entity
_description, _exportMoMLContents, _removePort, connectedPortList, connectedPorts, containedObjectsIterator, getAttribute, getPort, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts, setClassDefinition, uniqueName, validateSettables
 
Methods inherited from class ptolemy.kernel.InstantiableNamedObj
_setParent, exportMoML, getChildren, getElementName, getParent, getPrototypeList, isClassDefinition
 
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _attachText, _cloneFixAttributeFields, _debug, _debug, _debug, _debug, _debug, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, attributeList, attributeList, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, getAttribute, getAttributes, getChangeListeners, getClassName, getDerivedLevel, getDerivedList, getFullName, getModelErrorHandler, getName, getName, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, message, propagateValue, propagateValues, removeChangeListener, removeDebugListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setModelErrorHandler, setPersistent, setSource, toplevel, toString, workspace
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface ptolemy.actor.Actor
getDirector, getExecutiveDirector, getFunctionDependency, getManager, inputPortList, newReceiver, outputPortList
 
Methods inherited from interface ptolemy.actor.Executable
iterate, prefire, preinitialize, stop, stopFire, terminate
 
Methods inherited from interface ptolemy.kernel.util.Derivable
getDerivedLevel, getDerivedList, propagateValue
 
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getFullName, getName, getName
 

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.

Constructor Detail

Test

public Test(CompositeEntity container,
            java.lang.String name)
     throws NameDuplicationException,
            IllegalActionException
Construct an actor with an input multiport.

Parameters:
container - The container.
name - The name of this actor.
Throws:
IllegalActionException - If the entity cannot be contained by the proposed container.
NameDuplicationException - If the container already has an actor with this name.
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 matches, then output false (to indicate that the test is not complete yet) and return. Otherwise, throw an exception. 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.

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

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.