_trainingTokens = new ArrayList();
}
if (width == 1) {
if (input.hasToken(0)) {
Token token = input.get(0);
if (token instanceof ArrayToken) {
Token[] innerArrayToken = new Token[1];
innerArrayToken[0] = token;
_trainingTokens.add(innerArrayToken);
} else {
_trainingTokens.add(token);
}
}
} else {
ArrayList arrayList = new ArrayList();
for (int i = 0; i < width; i++) {
arrayList.add(input.get(i));
}
_trainingTokens.add(arrayList);
}
return;
}
if (_numberOfInputTokensSeen >= ((ArrayToken) (correctValues.getToken()))
.length()) {
// Consume and discard input values. We are beyond the end
// of the correctValues array.
for (int i = 0; i < width; i++) {
if (input.hasToken(i)) {
input.get(i);
}
}
// Indicate that the test has passed.
output.send(0, new BooleanToken(true));
return;
}
output.send(0, new BooleanToken(false));
Token referenceToken = ((ArrayToken) (correctValues.getToken()))
.getElement(_numberOfInputTokensSeen);
Token[] reference;
if ((width == 1) && !(referenceToken instanceof ArrayToken)) {
reference = new Token[1];
reference[0] = referenceToken;
} else {
try {
reference = ((ArrayToken) referenceToken).arrayValue();
} catch (ClassCastException ex) {
throw new IllegalActionException(this,
"Test fails in iteration " + _numberOfInputTokensSeen
+ ".\n" + "Width of input is " + width
+ ", but correctValues parameter "
+ "is not an array " + "of arrays.");
}
if (width != reference.length) {
throw new IllegalActionException(this,
"Test fails in iteration " + _numberOfInputTokensSeen
+ ".\n" + "Width of input is " + width
+ ", which does not match "
+ "the width of the "
+ _numberOfInputTokensSeen + "-th element of"
+ " correctValues, " + reference.length);
}
}
for (int i = 0; i < width; i++) {
if (!input.hasToken(i)) {
throw new IllegalActionException(this,
"Test fails in iteration " + _numberOfInputTokensSeen
+ ".\n" + "Empty input on channel " + i);
}
Token token = input.get(i);
boolean isClose;
try {
isClose = token.isCloseTo(reference[i], _tolerance)
.booleanValue()
|| token.isNil() && reference[i].isNil();
// Additional guards makes things slightly easier for
// Copernicus.
if (token instanceof ArrayToken
&& reference[i] instanceof ArrayToken) {
isClose |= _isCloseToIfNilArrayElement(token, reference[i],