Overview | Package | Class | Tree | Deprecated | Index | Help
| J avolution v5.2 (J2SE 1.5+)
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## javolution.testing
Class TimeContext

    java.lang.Object
      javolution.context.Context
          javolution.context.LogContext
              javolution.testing.TestContext
                  javolution.testing.TimeContext

All Implemented Interfaces:
  java.io.Serializable, XMLSerializable

    public abstract class TimeContext

extends TestContext

This class represents a `test context` specialized for measuring execution time.

`TimeContext` implementations may perform assertions based upon the execution time. For example:``

         class MyTestCase extends TestCase() {
              ...
              public void validate() {
                  long ns = TimeContext.getAverageTime("ns");
                  TimeContext.assertTrue(ns < 100); // Error if execution time is more than 100 ns.
                  ...
              }
         }

Version:
  5.2, August 5, 2007
Author:
  Jean-Marie Dautelle
See Also:
  Serialized Form

Field Summary
`static Configurable<java.lang.Class<? extends TimeContext>>` | `DEFAULT` Holds the time context default implementation (by default logs average and minimum execution time to `System.out`).
`static java.lang.Class<TimeContext>` | `REGRESSION` Holds an implementation which does not perform any logging but raises an `AssertionException` when an assertion fails, including any timing assertion.
`static Configurable<java.lang.Integer>` | `TEST_DURATION_MS` Holds the minimum duration of each test case execution (default 2000 ms).

Fields inherited from class javolution.context.LogContext
`CONSOLE, NULL, STANDARD, SYSTEM_OUT`

Fields inherited from class javolution.context.Context
`ROOT`

Constructor Summary
`TimeContext()`

Method Summary
`boolean` | `doAssertEquals(java.lang.String message, java.lang.Object expected, java.lang.Object actual)` Asserts that two objects are equal.
`void` | `doTest(TestCase testCase)` Executes the specified test case and logs the results.
`static TimeContext` | `enter()` Enters the `DEFAULT` time context.
`static TimeContext` | `exit()` Exits the current time context.
`static long` | `getAverageTime(java.lang.String unit)` Returns the average execution time of the latest execution performed or `-1` if the current context is not a time context.
`long` | `getAverageTimeInPicoSeconds()` Returns the average execution time of the latest execution stated in pico-seconds.
`static long` | `getMaximumTime(java.lang.String unit)` Returns the maximum execution time of the latest execution performed or `-1` if the current context is not a time context.
`long` | `getMaximumTimeInPicoSeconds()` Returns the maximmum execution time of the latest execution stated in pico-seconds.
`static long` | `getMinimumTime(java.lang.String unit)` Returns the minimum execution time of the latest execution performed or `-1` if the current context is not a time context.
`long` | `getMinimumTimeInPicoSeconds()` Returns the minimum execution time of the latest execution stated in pico-seconds.

Methods inherited from class javolution.testing.TestContext
`assertEquals, assertEquals, assertTrue, assertTrue, test`

Methods inherited from class javolution.context.LogContext
`enterAction, error, error, error, error, error, exitAction, getCurrent, getDefault, info, info, isErrorLogged, isInfoLogged, isWarningLogged, logError, logError, logInfo, logInfo, logWarning, logWarning, warning, warning`

Methods inherited from class javolution.context.Context
`enter, enter, exit, getOuter, getOwner, setCurrent, toString`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Field Detail

### REGRESSION

    public static final java.lang.Class<TimeContext> REGRESSION

  Holds an implementation which does not perform any logging but raises an `AssertionException` when an assertion fails, including any timing assertion.

### TEST_DURATION_MS

    public static final Configurable<java.lang.Integer> TEST_DURATION_MS

  Holds the minimum duration of each test case execution (default 2000 ms). The larger the number the more accurate is the average time result; but the longer it takes to run the test.

### DEFAULT

    public static final Configurable<java.lang.Class<? extends TimeContext>> DEFAULT

  Holds the time context default implementation (by default logs average and minimum execution time to `System.out`).

Constructor Detail

### TimeContext

    public TimeContext()

Method Detail

### enter

    public static TimeContext enter()

  Enters the `DEFAULT` time context.

  Returns:
    the time context being entered.

### exit

    public static TimeContext exit()

  Exits the current time context.

  Returns:
    the time context being exited.
  Throws:
    `java.lang.ClassCastException` - if the context is not a stack context.

### getMinimumTime

    public static long getMinimumTime(java.lang.String unit)

  Returns the minimum execution time of the latest execution performed or `-1` if the current context is not a time context.

  Parameters:
    `unit` - one of `"s", "ms", "us", "ns", "ps"`
  Returns:
    the minimum execution time stated in the specified unit.

### getAverageTime

    public static long getAverageTime(java.lang.String unit)

  Returns the average execution time of the latest execution performed or `-1` if the current context is not a time context.

  Parameters:
    `unit` - one of `"s", "ms", "us", "ns", "ps"`
  Returns:
    the average execution time stated in the specified unit.

### getMaximumTime

    public static long getMaximumTime(java.lang.String unit)

  Returns the maximum execution time of the latest execution performed or `-1` if the current context is not a time context.

  Parameters:
    `unit` - one of `"s", "ms", "us", "ns", "ps"`
  Returns:
    the maximum execution time stated in the specified unit.

### getMinimumTimeInPicoSeconds

    public long getMinimumTimeInPicoSeconds()

  Returns the minimum execution time of the latest execution stated in pico-seconds.

  Returns:
    the time in pico-seconds.

### getAverageTimeInPicoSeconds

    public long getAverageTimeInPicoSeconds()

  Returns the average execution time of the latest execution stated in pico-seconds.

  Returns:
    the time in pico-seconds.

### getMaximumTimeInPicoSeconds

    public long getMaximumTimeInPicoSeconds()

  Returns the maximmum execution time of the latest execution stated in pico-seconds.

  Returns:
    the time in pico-seconds.

### doTest

    public void doTest(TestCase testCase)

  Description copied from class: `TestContext`
  Executes the specified test case and logs the results.

  Specified by:
    `doTest` in class `TestContext`
  Parameters:
    `testCase` - the test case being executed.

### doAssertEquals

    public boolean doAssertEquals(java.lang.String message,
                                  java.lang.Object expected,
                                  java.lang.Object actual)

  Description copied from class: `TestContext`
  Asserts that two objects are equal.

  Specified by:
    `doAssertEquals` in class `TestContext`
  Parameters:
    `message` - the message displayed if assert fails (can be `null`)
    `expected` - the expected result (can be `null`).
    `actual` - the actual result (can be `null`).
  Returns:
    `true` if both expected and actual are equal; `false` otherwise.

Overview | Package | Class | Tree | Deprecated | Index | Help
| J avolution v5.2 (J2SE 1.5+)
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2005 - 2007 Javolution.