File: add.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 (59 lines) | stat: -rw-r--r-- 1,086 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
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 579)],
	[qw(890 135 925)],
	[qw(456 879 225)],
	);

eval {	
	foreach my $triad ( @triads )
		{
		my( $n, $m, $expected ) = @$triad;
		
		my $sum1 = Math::NoCarry::add( $n, $m );
		my $sum2 = Math::NoCarry::add( $m, $n );
		
		die "Different results for different orders!\n" .
			"[$n + $m] gave [$sum1]\n[$m + $n] gave [$sum2]\n"
			if $sum1 != $sum2;
		
		die "[$n + $m] gave [$sum1], but I expected [$expected]\n"
			unless $sum1 == $expected;
		}
	};
print STDERR $@ if $@;
print $@ ? 'not ' : '', "ok\n";
	
eval {	
	foreach my $triad ( @triads )
		{
		foreach my $n ( @$triad )
			{
			my $sum = Math::NoCarry::add( $n );
			
			die "[$n] gave [$sum], but I expected [$n]\n"
				unless $sum == $n;
			}
		}
	};
print STDERR $@ if $@;
print $@ ? 'not ' : '', "ok\n";

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