File: docs-eg.t

package info (click to toggle)
libtest-lectrotest-perl 0.5001-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 412 kB
  • sloc: perl: 1,808; sh: 13; makefile: 6
file content (57 lines) | stat: -rwxr-xr-x 1,205 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/perl

use warnings;
use strict;

use Test::LectroTest;

=head1 NAME

t/docs-eg.t - test cases for examples from documentation

=head1 SYNOPSIS

  perl -Ilib t/docs-eg.t

=head1 DESCRIPTION

These test cases make sure that the examples in the documentation work.

=head2 Examples from Property.pm

=cut

sub my_sqrt { sqrt($_[0]) }

my $epsilon = 0.000_001;

Property {
      ##[ x <- Float ]##
      return $tcon->retry if $x < 0;
      $tcon->label("less than 1") if $x < 1;
      my $sx = my_sqrt( $x );
      abs($sx * $sx - $x) < $epsilon;
}, name => "my_sqrt satisfies defn of square root";

sub my_thing_to_test { 1 }

Property {
    ##[ i <- Int, delta <- Float(range=>[0,1]) ]##
    my $lo_val = my_thing_to_test($i);
    my $hi_val = my_thing_to_test($i + $delta);
    1;
}, name => "my_thing_to_test ignores fractions" ;

{
  my $prop = Test::LectroTest::Property->new(
    inputs => [ i => Int, delta => Float(range=>[0,1]) ],
    test => sub {
        my ($tcon, $delta, $i) = @_;
        my $lo_val = my_thing_to_test($i);
        my $hi_val = my_thing_to_test($i + $delta);
    },
    name => "my_thing_to_test ignores fractions"
  ) ;
  push @Test::LectroTest::props, $prop;
}