Class Test
- java.lang.Object
-
- 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)
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class ptolemy.kernel.Entity
Entity.ContainedObjectsIterator
-
-
Field Summary
Fields Modifier and Type Field Description 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, _matchedValues, _numberOfInputTokensSeen, _tolerance, _trainingTokens, correctValues, requireAllCorrectValues, requireOrderedValues, tolerance, TRAINING_MODE_ERROR_MESSAGE, trainingMode
-
Fields inherited from class ptolemy.actor.TypedAtomicActor
_typesValid
-
Fields inherited from class ptolemy.actor.AtomicActor
_actorFiringListeners, _initializables, _notifyingActorFiring, _stopRequested
-
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _deferChangeRequests, _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
Constructors Constructor Description Test(CompositeEntity container, java.lang.String name)
Construct an actor with an input multiport.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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
_checkRangeOfTolerance, _customTypeConstraints, _isClose, _isCloseToIfNilArrayElement, _isCloseToIfNilRecordElement, attributeChanged, clone, initialize, wrapup
-
Methods inherited from class ptolemy.actor.TypedAtomicActor
_containedTypeConstraints, _defaultTypeConstraints, _fireAt, _fireAt, attributeTypeChanged, clone, isBackwardTypeInferenceEnabled, newPort, typeConstraintList, typeConstraints
-
Methods inherited from class ptolemy.actor.AtomicActor
_actorFiring, _actorFiring, _declareDelayDependency, 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
_addPort, _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, _containedDecorators, _copyChangeRequestList, _debug, _debug, _debug, _debug, _debug, _executeChangeRequests, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _notifyHierarchyListenersAfterChange, _notifyHierarchyListenersBeforeChange, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, addHierarchyListener, attributeDeleted, attributeList, attributeList, decorators, 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, notifyOfNameChange, propagateValue, propagateValues, removeAttribute, removeChangeListener, removeDebugListener, removeHierarchyListener, 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.kernel.util.Derivable
getDerivedLevel, getDerivedList, propagateValue
-
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
-
-
-
-
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 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 interfaceExecutable
- Overrides:
fire
in classNonStrictTest
- 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 interfaceExecutable
- Overrides:
postfire
in classNonStrictTest
- Returns:
- True.
-
-