File: Tester.pm

package info (click to toggle)
libalgorithm-combinatorics-perl 0.27-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, sid, stretch
  • size: 216 kB
  • ctags: 36
  • sloc: perl: 399; makefile: 2
file content (44 lines) | stat: -rw-r--r-- 1,037 bytes parent folder | download | duplicates (3)
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
package Tester;

use strict;

use Test::More;

sub __new {
	my ($class, $coderef, $comparator) = @_;
	$comparator = \&Test::More::is_deeply if not $comparator;
	bless { to_test => $coderef, comparator => $comparator }, $class;
}

# Here @rest is mean to be either (@data) or (@data, $k).
sub __test {
	my ($self, $expected, @rest) = @_;

	my @result = ();
	my $iter = $self->{to_test}(@rest);
	while (my $c = $iter->next) {
	    push @result, $c;
	}
	$self->{comparator}($expected, \@result, "");

	@result = $self->{to_test}(@rest);
	$self->{comparator}($expected, \@result, "");

    if (@rest > 1) {
        # as of today this means we've got a $k
        # test we don't assume $k is an IV in XS
        $rest[1] = "$rest[1]";

        @result = ();
        $iter = $self->{to_test}(@rest);
        while (my $c = $iter->next) {
            push @result, $c;
        }
        $self->{comparator}($expected, \@result, "");

        @result = $self->{to_test}(@rest);
        $self->{comparator}($expected, \@result, "");
    }
}

1;