com.topcoder.shared.problem
Class TestCase

java.lang.Object
  |
  +--com.topcoder.shared.problem.BaseElement
        |
        +--com.topcoder.shared.problem.TestCase
All Implemented Interfaces:
java.lang.Cloneable, com.topcoder.shared.netCommon.CustomSerializable, Element, java.io.Serializable

public class TestCase
extends com.topcoder.shared.problem.BaseElement
implements Element

This class represents a test case. It can be either an example test case (as shown in a problem statement), or it may represent a system test case (the former are actually instances of the latter). All test cases consist of one or more input strings and one output string. Example test cases may have an optional annotation, represented as an Element.

Author:
Logan Hanks
See Also:
Element, Serialized Form

Field Summary
static java.lang.String ERROR
          What the output will be equal to if an error occurred during generation of the output.
static java.lang.String UNKNOWN_OUTPUT
          What the output will be equal to if the output is unknown.
 
Constructor Summary
TestCase()
          Empty constructor required by custom serialization.
TestCase(java.lang.String[] input, Element annotation, boolean example)
          Constructs a TestCase whos output is yet unknown.
TestCase(java.lang.String[] input, java.lang.String output, boolean example)
          Constructs an unannotated test case.
TestCase(java.lang.String[] input, java.lang.String output, Element annotation, boolean example)
           
 
Method Summary
 void customReadObject(com.topcoder.shared.netCommon.CSReader reader)
          Custom serialization
 void customWriteObject(com.topcoder.shared.netCommon.CSWriter writer)
          Custom serialization
static java.lang.String encodeHTML(java.lang.String text)
          Utility function for encoding HTML entities in text.
 boolean equals(java.lang.Object obj)
          Whether this test case equals another test case.
 Element getAnnotation()
          Returns the annotation associated with this test case.
 java.lang.String[] getInput()
          Returns the string representations of the input values as an array.
 java.lang.String getOutput()
          Returns the string representation of the expected output for this test case.
 ElementRenderer getRenderer()
          Returns this elements renderer.
 boolean isExample()
          True if this test case is an example test case.
 void setExample(boolean example)
          Set's whether the test case is an example or system test case.
 void setOutput(java.lang.String output)
          Set's the string representation of the expected output for this test case.
 void setRenderer(ElementRenderer renderer)
          Sets the renderer for this element.
 java.lang.String toXML()
          Returns the XML representation of this element.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.topcoder.shared.problem.Element
getRenderer, setRenderer
 

Field Detail

UNKNOWN_OUTPUT

public static final java.lang.String UNKNOWN_OUTPUT
What the output will be equal to if the output is unknown.

See Also:
Constant Field Values

ERROR

public static final java.lang.String ERROR
What the output will be equal to if an error occurred during generation of the output.

See Also:
Constant Field Values
Constructor Detail

TestCase

public TestCase()
Empty constructor required by custom serialization.


TestCase

public TestCase(java.lang.String[] input,
                java.lang.String output,
                boolean example)
Constructs an unannotated test case.

Parameters:
input - An array of input values. The first value should be the value for the first argument, etc.
output - A string representation of the expected output for this test case.
example - Specifies whether or not this is an example test case.

TestCase

public TestCase(java.lang.String[] input,
                java.lang.String output,
                Element annotation,
                boolean example)
Parameters:
input - An array of input values. The first value should be the value for the first argument, etc.
output - A string representation of the expected output for this test case.
annotation - An Element representing a writer's annotation, or explanation of this test case. This value can be null if no annotation exists, and should only be non-null when example is true.
example - Specifies whether or not this is an example test case.
See Also:
Element

TestCase

public TestCase(java.lang.String[] input,
                Element annotation,
                boolean example)
Constructs a TestCase whos output is yet unknown.

Parameters:
input - An array of input values. The first value should be the value for the first argument, etc.
annotation - An Element representing a writer's annotation, or explanation of this test case. This value can be null if no annotation exists, and should only be non-null when example is true.
example - Specifies whether or not this is an example test case.
See Also:
Element
Method Detail

customWriteObject

public void customWriteObject(com.topcoder.shared.netCommon.CSWriter writer)
                       throws java.io.IOException
Custom serialization

Specified by:
customWriteObject in interface Element
Parameters:
writer - the writer to write to.
Throws:
java.io.IOException - if an I/O error has occurred in the stream that backs the writer.

customReadObject

public void customReadObject(com.topcoder.shared.netCommon.CSReader reader)
                      throws java.io.IOException,
                             java.io.ObjectStreamException
Custom serialization

Specified by:
customReadObject in interface Element
Parameters:
reader - the reader to read from.
Throws:
java.io.ObjectStreamException - if the information that is read is inconsistent (stream corrupted or incompatibility between writers and readers)
java.io.IOException - if an I/O error has occurred in the stream that backs the reader.

isExample

public boolean isExample()
True if this test case is an example test case.

Returns:
true if the test case is an example or false if it's a system test case.

setExample

public void setExample(boolean example)
Set's whether the test case is an example or system test case.

Parameters:
example - true if the test case is an example or false if it's a system test case.

getInput

public java.lang.String[] getInput()
Returns the string representations of the input values as an array. The order of the array corresponds to the order of parameters to the solution. The values should be consistent with the data types returned by the problem component.

Returns:
the string representations of the input values as an array.
See Also:
ProblemComponent.getParamTypes()

setOutput

public void setOutput(java.lang.String output)
Set's the string representation of the expected output for this test case.

Parameters:
output - the string representation of the expected output for this test case.

getOutput

public java.lang.String getOutput()
Returns the string representation of the expected output for this test case. The string value should be consistent with the data type returned by the problem component.

Returns:
The string representation of the expected output for this test case.
See Also:
ProblemComponent.getReturnType()

getAnnotation

public Element getAnnotation()
Returns the annotation associated with this test case. Returns null if no annotation exists.

Returns:
the annotation associated with this test case or null if none.

toXML

public java.lang.String toXML()
Returns the XML representation of this element. Formatted like <test-case example="1"><input>encoded value</input><input>...</input><output>encoded value</output><annotation>text</annotation></test-case>.

Specified by:
toXML in interface Element
Returns:
the XML representation of this element.

equals

public boolean equals(java.lang.Object obj)
Whether this test case equals another test case.

Overrides:
equals in class java.lang.Object
Returns:
true if the same, false if not.

setRenderer

public void setRenderer(ElementRenderer renderer)
Sets the renderer for this element.

Specified by:
setRenderer in interface Element
Parameters:
renderer - the element renderer.
See Also:
ElementRenderer

getRenderer

public ElementRenderer getRenderer()
Returns this elements renderer.

Specified by:
getRenderer in interface Element
Returns:
this elements renderer.
See Also:
ElementRenderer

encodeHTML

public static java.lang.String encodeHTML(java.lang.String text)
Utility function for encoding HTML entities in text. All occurrences of the <, >, and & characters are converted to &lt;, &gt;, and &amp;, respectively.

Parameters:
text - the text to encode.
Returns:
the encoded text.