File: multiply.t

package info (click to toggle)
libmath-nocarry-perl 1.117-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 160 kB
  • sloc: perl: 60; makefile: 2
file content (68 lines) | stat: -rw-r--r-- 1,240 bytes parent folder | download | duplicates (5)
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
BEGIN { print "1..4\n"; }

END { print "not ok\n" unless $loaded }

use Math::NoCarry;

$loaded = 1;

print "ok\n";

my @triads = (
	[qw( 123  456  43878)],
	[qw(-123 -456  43878)],
	[qw(-123  456 -43878)],
	[qw( 123 -456 -43878)],
	
	[qw(456 123 43878)],
	[qw(456 879 28974)],
	[qw(879 456 28974)],

	[qw(  890 135  83750)],
	[qw( 135  890  83750)],
	[qw(-135  890 -83750)],
	[qw( 135 -890 -83750)],
	[qw(-135 -890  83750)],

	[qw(500 321 50500)],
	[qw(321 500 50500)],
	);

eval {	
	foreach my $triad ( @triads )
		{
		my( $n, $m, $expected ) = @$triad;
		
		my $product = Math::NoCarry::multiply( $n, $m );
				
		die "[$n x $m] gave [$product], but I expected [$expected]\n"
			unless $product == $expected;
		}
	};
print STDERR $@ if $@;
print $@ ? 'not ' : '', "ok\n";

eval {	
	foreach my $triad ( @triads )
		{
		foreach my $n ( @$triad )
			{
			my $product = Math::NoCarry::multiply( $n );
			
			die "[$n] gave [$product], but I expected [$n]\n"
				unless $product == $n;
			}
		}
	};
print STDERR $@ if $@;
print $@ ? 'not ' : '', "ok\n";

eval {	
	my $product = Math::NoCarry::multiply();
			
	die "[NULL] gave [$product], but I expected [FALSE]\n"
				if $product;
	};
print STDERR $@ if $@;
print $@ ? 'not ' : '', "ok\n";