ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/Algorithm-FEC/t/00_load.t
Revision: 1.4
Committed: Sat Sep 13 21:16:33 2003 UTC (23 years ago) by root
Content type: application/x-troff
Branch: MAIN
CVS Tags: rel-1_0
Changes since 1.3: +8 -9 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.2 BEGIN { $| = 1; print "1..30\n"; }
2 root 1.1 END {print "not ok 1\n" unless $loaded;}
3 root 1.3 use Algorithm::FEC;
4 root 1.1 $loaded = 1;
5    
6     use File::Temp;
7    
8 root 1.3 my $fec = new Algorithm::FEC 3, 5, 70;
9 root 1.1
10     my $test = 0;
11    
12     sub ok($) {
13     $test++;
14     print $_[0] ? "ok $test\n" : "not ok $test\n";
15     }
16    
17     my @files = map {
18     $fd = tmpfile ();
19     syswrite $fd, $_ x 70;
20     $_ < 2 ? $fd : [$fd, 0];
21     } 1..3;
22    
23     ok 1;
24    
25 root 1.4 $fec->set_encode_blocks (\@files);
26 root 1.1
27     ok 1;
28    
29     my @blk;
30    
31     for (0..4) {
32     ok 1;
33    
34     $blk[$_] = $fec->encode ($_);
35     }
36    
37     ok ($blk[0] eq "1" x 70);
38     ok ($blk[1] eq "2" x 70);
39     ok ($blk[2] eq "3" x 70);
40     ok ($blk[3] eq "%" x 70);
41     ok ($blk[4] eq "Y" x 70);
42    
43     for ([[0,1,2],[0,1,2]],
44 root 1.4 [[0,2,1],[0,1,2]],
45     [[0,2,3],[0,3,2]],
46     [[4,3,1],[4,1,3]]) {
47 root 1.1 my ($idx1, $idx2) = @$_;
48    
49     my @blks;
50    
51     ok 1;
52     my $i;
53     for (@$idx1) {
54     $blks[$i++] = $_ < 3 ? $files[$_] : $blk[$_];
55     }
56    
57 root 1.4 $fec->set_decode_blocks (\@blks, $idx1);
58     $fec->decode;
59 root 1.1
60     ok 1;
61    
62     ok ("@$idx1" eq "@$idx2");
63    
64 root 1.4 for (0 .. $#$idx1) {
65 root 1.1 next if ref $blks[$_];
66 root 1.4 ok (($_+1) x 70 eq $blks[$_]);
67 root 1.1 }
68     }
69 root 1.2
70     ok 1;
71    
72     my $a = "a" x 70;
73     my $b = "b" x 70;
74    
75     $fec->copy ($b, $a);
76    
77 root 1.3 ok ($a eq $b);
78     ok ($a eq "b" x 70);
79 root 1.1