|
NAMETest::RandomResults - Test non-deterministic functionsDESCRIPTIONThis module aims to provide ways of testing functions that are meant to return results that are random; that is, non-deterministic functions.Some of the tests provided here might be easily achieved with other testing modules. The reason why they're here is that this way users become aware of how to test their non-deterministic functions. NOTICEThis is a work in progress. Comments are welcome.SYNOPSISuse Test::More plan => $Num_Tests; use Test::RandomResults; is_in( my_function, [ $list, $of, $items ], "result is inside list" ); in_between( my_function, sub { $_[0] cmp $_[1] }, 1, 10, "result between 1 and 10"); length_lt( my_function, $limit, "length less than $limit"); length_le( my_function, $limit, "length less or equal to $limit"); length_eq( my_function, $limit, "length equal to $limit"); length_ge( my_function, $limit, "length greater of equal to $limit"); length_gt( my_function, $limit, "length greater than $limit"); SPECIAL FEATURESWhenever "Test::RandomResults" is invoked, a new seed is generated and outputed as diagnostics. This is done so that you can use it to debug your code, if needed.FUNCTIONSis_inTests if an element belongs to an array.is_in( my_function, [1, 2, 3], 'either 1, 2 or 3'); in_betweenTests if an element is within two boundaries.The second parameter to this function is what it uses to do the comparisons. To compare strings: in_between( my_function, { $_[0] cmp $_[1] }, "aaa", "zzz", 'result is between "aaa" and "zzz"' ); To compare numbers: in_between( my_function, { $_[0] <=> $_[1] }, 1, 10, 'result is between 1 and 10' ); To compare something else: in_between( my_function, &your_function_here, $lower_boundary, $upper_boundary, 'result is between boundaries' ); As you can see, the function should use $_[0] and $_[1] to do the comparison. As with <=> and cmp, the function should return 1, 0 or -1 depending on whether the first argument ($_[0]) is greater, equal to, or less than the second one ($_[1]). "in_between" swaps the lower and upper limits, if need be (this means that checking whether a value is between 1 and 10 is the same as checking between 10 and 1). length_ltTests if length is less than a limit.length_lt( my_function, $limit, "length less than $limit"); length_leTests if length is less or equal to a limit.length_le( my_function, $limit, "length less or equal to $limit"); length_eqTests if length is equal to a limit.length_eq( my_function, $limit, "length equal to $limit"); length_geTests if length is greater of equal to a limit.length_ge( my_function, $limit, "length greater of equal to $limit"); length_gtTests if length is greater than a limit.length_gt( my_function, $limit, "length greater than $limit"); TO DO* Check if N results of a function are evenly_distributed* Allow the user to choose the seed when invoking "Test::RandomResults" AUTHORJose Castro, "<cog@cpan.org>"BUGSPlease report any bugs or feature requests to "bug-test-randomresults@rt.cpan.org", or through the web interface at <http://rt.cpan.org>. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.COPYRIGHT & LICENSECopyright 2005 Jose Castro, All Rights Reserved.This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Visit the GSP FreeBSD Man Page Interface. |