|
Rosetta 3.5
|
UTracer is an object similar to core::util Tracer (see Tracer, tool for debug IO Tracer documantaion page for more info). It main purpose is to capture user output, compare output with previously saved version and save new version in to '._tmp_' file. In addition UTracer object can be used to capture output of specified channels inside core or protocols lib and compare this outputs to a file version.
To create UTracer object you need to supply one argument – name of the file to which output will be compared. For example:
will create UTracer object that will compare all output going in to it to a content of a file “MyFile.u”. (Please use .u extension as default for UTracer files). When doing a comparison current version of output will be saved to a ._tmp_ file, in this case it will be file 'MyFile.u._tmp_'.
To use UTracer object simply send output to it using '<<' C++ operator. In additional to handling standard build-in C++ type it is possible to serialize vector, vector1 and map's type. For example:
Note: As with Tracer object symbol '\n' should be used for a new line, instead of using std::endl line symbol.
Currently only float point number can be compared with a specified precisions. It is possible to specify precisions in two ways: absolute and relative.
Simply calling 'UTracer & delta(double absolute_delta)' will set current acceptble delta for float numbers. Default delta for a new UTracer object is 1e-200. Example:
For specifying relative precisions use 'UTracer & relative(double relative_precision)'. When UTracer compare using ralative precision it convert it first to a absolute delta value using this function: delta = (original_value + new_value)/2. * relative_precision. Where original_value and new_value is a value read from .u file and value serialized to UTracer. Example:
It is possible to effectively use absolute and relative precision in the same time. If both precisions are specified effective delta will be calculated as maximum from absolute and relative delta. Suppose we have an array of values ranged from 0 to 100 that we want compare following way: all values should not be different from the original by more then 5% and in the same time we would like to consider value equal if they both below .1 in absolute value. Using UTracer we can do this following way:
Trick: to compare integer number with a precision convert them first to double, and then use UTracer functions 'delta' and 'relative' to compare.
It is also possible to use UTracer to monitor and compare output of other Tracer channels. This sometimes can be very useful to test libraries inner parts. For example suppose that we have MyMover class that we want to write unit test for. And value that we want to test generated as local variables in apply() member function and did not saved as a class members. To test such values we can do the following:
1.8.4