ptolemy.actor.lib
Class Test

java.lang.Object
  extended by ptolemy.kernel.util.NamedObj
      extended by ptolemy.kernel.InstantiableNamedObj
          extended by ptolemy.kernel.Entity
              extended by ptolemy.kernel.ComponentEntity
                  extended by ptolemy.actor.AtomicActor
                      extended by ptolemy.actor.TypedAtomicActor
                          extended by ptolemy.actor.lib.Sink
                              extended by ptolemy.actor.lib.NonStrictTest
                                  extended by ptolemy.actor.lib.Test
All Implemented Interfaces:
java.io.Serializable, 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.

Since:
Ptolemy II 1.0
Version:
$Id: Test.java 57040 2010-01-27 20:52:32Z cxh $
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/interfaces 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
_firedOnce, _initialized, _iteration, _numberOfInputTokensSeen, _tolerance, _trainingTokens, correctValues, requireAllCorrectValues, tolerance, TRAINING_MODE_ERROR_MESSAGE, trainingMode
 
Fields inherited from class ptolemy.actor.lib.Sink
input
 
Fields inherited from class ptolemy.actor.AtomicActor
_actorFiringListeners, _initializables, _notifyingActorFiring, _stopRequested
 
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _elementName, _isPersistent, _verbose, _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
_isCloseToIfNilArrayElement, _isCloseToIfNilRecordElement, attributeChanged, clone, initialize, isRunningNightlyBuild, wrapup
 
Methods inherited from class ptolemy.actor.TypedAtomicActor
_addPort, _fireAt, _fireAt, attributeTypeChanged, clone, newPort, typeConstraintList, typeConstraints
 
Methods inherited from class ptolemy.actor.AtomicActor
_actorFiring, _actorFiring, addActorFiringListener, addInitializable, connectionsChanged, createReceivers, declareDelayDependency, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, isFireFunctional, isStrict, iterate, newReceiver, outputPortList, prefire, preinitialize, pruneDependencies, recordFiring, removeActorFiringListener, removeDependency, removeInitializable, setContainer, stop, stopFire, terminate
 
Methods inherited from class ptolemy.kernel.ComponentEntity
_adjustDeferrals, _checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, isAtomic, isOpaque, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, propagateExistence, setName
 
Methods inherited from class ptolemy.kernel.Entity
_description, _exportMoMLContents, _removePort, _validateSettables, connectedPortList, connectedPorts, containedObjectsIterator, getAttribute, getPort, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts, setClassDefinition, uniqueName
 
Methods inherited from class ptolemy.kernel.InstantiableNamedObj
_setParent, exportMoML, getChildren, getElementName, getParent, getPrototypeList, isClassDefinition, isWithinClassDefinition
 
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _debug, _debug, _debug, _debug, _debug, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _propagateValue, _recordDecoratedAttributes, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, attributeList, attributeList, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttributes, getChangeListeners, getClassName, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getFullName, getModelErrorHandler, getName, getName, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, propagateValue, propagateValues, removeChangeListener, removeDebugListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, validateSettables, workspace
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface ptolemy.actor.Actor
createReceivers, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, newReceiver, outputPortList
 
Methods inherited from interface ptolemy.actor.Executable
isFireFunctional, isStrict, iterate, prefire, stop, stopFire, terminate
 
Methods inherited from interface ptolemy.actor.Initializable
addInitializable, preinitialize, removeInitializable
 
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getContainer, getDisplayName, getFullName, getName, getName, setName
 
Methods inherited from interface ptolemy.kernel.util.Derivable
getDerivedLevel, getDerivedList, propagateValue
 

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 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.