File: Multiset.t

package info (click to toggle)
libmath-gsl-perl 0.45-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 192,156 kB
  • sloc: ansic: 895,524; perl: 24,682; makefile: 12
file content (99 lines) | stat: -rw-r--r-- 1,993 bytes parent folder | download | duplicates (4)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package Math::GSL::Multiset::Test;
use base q{Test::Class};
use strict;
use warnings;
use Test::Most;
use Math::GSL           qw/:all/;
use Math::GSL::Test     qw/:all/;
use Math::GSL::Errno    qw/:all/;
use Math::GSL::Multiset qw/:all/;

BEGIN{ gsl_set_error_handler_off(); }

sub constructor_1_15 : Test {
	return "GSL >= 1.16" if gsl_version() > v1.15;

	dies_ok { Math::GSL::Multiset->new(10,20); }, 
		"This version of GSL doesn't support k > n";
}

sub constructor : Test(5) {
	my ($k,$n) = (10,20);
	my $ms = Math::GSL::Multiset->new($n, $k);

	isa_ok($ms, "Math::GSL::Multiset");
	is $ms->{k}, $k;
	is $ms->{n}, $n;
	is $ms->k, $ms->{k};
	is $ms->n, $ms->{n};
}

sub clone: Test(3) {
	my ($k,$n) = (10,20);
	my $ms = Math::GSL::Multiset->new($n, $k);
	$ms->init_last;

	my $clone = $ms->clone();

	is $ms->k, $clone->k;
	is $ms->n, $clone->n;
	my $allOK = 1;
	for (my $i = 0; $i < $k; $i++) {
		$allOK = 0 if $ms->get($i) != $clone->get($i)
	}
	ok $allOK;
}

sub list : Test {
	my ($k,$n) = (10,20);
	my $ms = Math::GSL::Multiset->new($n, $k);
	$ms->next;
	is_deeply([$ms->to_list], [0,0,0,0,0,0,0,0,0,1]);
}

sub next_prev : Test(3) {
	my ($k,$n) = (10,20);
	my $ms = Math::GSL::Multiset->new($n, $k);
	$ms->next;
	is $ms->get($k-1) => 1;
	$ms->next;
	is $ms->get($k-1) => 2;
	$ms->prev;
	is $ms->get($k-1) => 1;
}

sub init : Test(2) {
	my ($k,$n) = (10,20);
	my $ms = Math::GSL::Multiset->new($n, $k);
	$ms->init_last;
	my $allOK = 1;
	for (my $i = 0; $i < $k; $i++) {
		$allOK = 0 if $ms->get($i) != ($n-1);
	}
	ok $allOK;

	$ms->init_first;
	$allOK = 1;
	for (my $i = 0; $i < $k; $i++) {
		$allOK = 0 if $ms->get($i) != 0;
	}
	ok $allOK;

}

sub get : Test(3) {
	my ($k,$n) = (10,20);
	my $ms = Math::GSL::Multiset->new($n, $k);	
	throws_ok { $ms->get(-1) } qr /out of range.*0 <= i < $k/;
	throws_ok { $ms->get($k) } qr /out of range.*0 <= i < $k/;
	
	my $allOK = 1;
	for (my $i = 0; $i < $k; $i++) {
		$allOK = 0 if $ms->get($i) != 0;
	}
	ok $allOK;
}



Test::Class->runtests;