Lab::Test -- Shared test routines for Lab::Measurement.
use Lab::Test import => [qw/file_ok compare_ok .../]; file_ok($filename, "file contents", "contents are equal"); file_filter_ok($filename, "line 1\nline 2\n", qr/ *$/m, "contents equal after removing trailing ws from each line"); compare_ok($file1, $file2, "files have same contents"); is_relative_error(10, 11, 0.2, "relative error of 10 and 11 is smaller than 20 percent"); is_num(0.7, 0.7, "numbers are equal"); is_float(1, 1.000000000000001, "floating point numbers are almost equal"); is_absolute_error(10, 11, 2, "absolute error of 10 and 11 is smaller than 2"); looks_like_number_ok("100e2", "'100e2' looks like a number"); set_get_test( instr => $instr, getter => 'get_amplitude', setter => 'set_amplitude', cache => 'cached_amplitude', values => [0.1, 1, 10], ); scpi_set_get_test( instr => $instr, func => 'sense_sweep_points', values => [1, 100, 10000], );
Collection of testing routines. This module can be used together with other Test::Builder-based modules like Test::More.
All functions are exported only on request.
Succeed if $file exists and it's contents are equal to $expected_contents. Uses binary comparison and $expected_contents may not have the unicode flag set.
$file
$expected_contents
Like file_ok but filter the contents of $file with s/$filter//g before comparing with expected_contents.
s/$filter//g
expected_contents
Succeed if $file exists and it's contents are equal to $expected_contents. On reading the file, convert CR-LF to LF. Uses binary comparison and $expected_contents may not have the unicode flag set.
Should be only needed to test legacy code. New code should always use binary files, not text files (Set binmode on your handles).
Succeed if both files exists and their contents are equal.
Succeed if the relative error between $got and $expect is smaller or equal than $error. Relative error is defined as abs(($got - $expect) / $expect).
$got
$expect
$error
abs(($got - $expect) / $expect)
If the absolute value of $got or $expect is smaller than DBL_MIN, that number replaced with DBL_MIN before computing the relative error. This is done to avoid division by zero. Two denormals will always compare equal.
Check for $got == $expect. This is unlike Test::More::is, which tests for $got eq $expect.
$got == $expect
Test::More::is
$got eq $expect
Compare floating point numbers.
Equivalent to is_relative_error($got, $expect, 1e-14, $name).
is_relative_error($got, $expect, 1e-14, $name)
1e-14 is about 100 times bigger than DBL_EPSILON. The test will succeed even if the numbers are tainted by multiple rounding operations.
1e-14
Similar to is_relative_error, but uses the absolute error.
is_relative_error
Checks if Scalar::Util's looks_like_number returns true for $number.
looks_like_number
$number
For formatting of floating point numbers perl's printf function relies on the system's printf.
On some platforms, most notably MS-W32, it is not compatible with C99. E.g. you get 1.000000e+001 instead of 1.000000e+01.
This routine skips the test, if a broken printf is detected.
set_get_test( instr => $instr, getter => 'get_amplitude', setter => 'set_amplitude', cache => 'cached_amplitude', # optional values => [0.1, 1, 10], is_numeric => 1, # this is default );
Try the setter, getter and cache for each value in values. Check that the getter and cache methods return the correct value. For non-numeric string values, set is_numeric to 0.
setter
getter
cache
values
is_numeric
scpi_set_get_test( instr => $instr, func => 'sense_sweep_points', values => [1, 100, 10000], is_numeric => 1, # this is default );
Like set_get_test, but assume that the getter, setter and cache are called "${func}_query", $func and "cached_$func" respectively.
set_get_test
"${func}_query"
$func
"cached_$func"
To install Lab::Measurement, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Lab::Measurement
CPAN shell
perl -MCPAN -e shell install Lab::Measurement
For more information on module installation, please visit the detailed CPAN module installation guide.