File: copy-mbi.t

package info (click to toggle)
libmath-bigint-perl 1.999838-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 9,424 kB
  • sloc: perl: 10,236; pascal: 5,387; makefile: 2
file content (84 lines) | stat: -rw-r--r-- 2,331 bytes parent folder | download
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
# -*- mode: perl; -*-

use strict;
use warnings;

use Math::BigInt;
use Scalar::Util qw< refaddr >;

use Test::More tests => 2;

my $LIB = Math::BigInt -> config('lib');

my $x = Math::BigInt -> new("314159");
my $y;

# testing copy() as an instance method

$y = $x -> copy();
subtest '$y = $x -> copy()' => sub {
    plan tests => 13;

    # object

    ok(defined($y), '$y is defined');
    is(ref($y), 'Math::BigInt', '$y has the right class');
    isnt(refaddr($y), refaddr($x), '$y is a different object than $x');

    # sign

    ok(defined($y->{sign}), 'sign of $y is defined');
    is(ref($y->{sign}), '', 'sign of $y is not a reference');
    is($y->{sign}, $x->{sign}, 'sign of $y is correct');

    # mantissa

    ok(defined($y->{value}), 'mantissa of $y is defined');
    is(ref($y->{value}), ref($x->{value}),
       'mantissa of $y and $x use the same reference type');
    isnt(ref($y->{value}), '', 'mantissa of $y is a reference');
    isnt(refaddr($y->{value}), refaddr($x->{value}),
      'mantissa of $y is not the mantissa of $x');
    is($LIB->_str($y->{value}), $LIB->_str($x->{value}),
       'mantissa of $y is correct');

    # accuracy and precision

    is($y->{_a}, $x->{_a}, 'accuracy');
    is($y->{_p}, $x->{_p}, 'precision');
};

# testing copy() as a class method

$y = Math::BigInt -> copy($x);
subtest '$y = Math::BigInt -> copy($x)' => sub {
    plan tests => 13;

    # object

    ok(defined($y), '$y is defined');
    is(ref($y), 'Math::BigInt', '$y has the right class');
    isnt(refaddr($y), refaddr($x), '$y is a different object than $x');

    # sign

    ok(defined($y->{sign}), 'sign of $y is defined');
    is(ref($y->{sign}), '', 'sign of $y is not a reference');
    is($y->{sign}, $x->{sign}, 'sign of $y is correct');

    # mantissa

    ok(defined($y->{value}), 'mantissa of $y is defined');
    is(ref($y->{value}), ref($x->{value}),
       'mantissa of $y and $x use the same reference type');
    isnt(ref($y->{value}), '', 'mantissa of $y is a reference');
    isnt(refaddr($y->{value}), refaddr($x->{value}),
      'mantissa of $y is not the mantissa of $x');
    is($LIB->_str($y->{value}), $LIB->_str($x->{value}),
       'mantissa of $y is correct');

    # accuracy and precision

    is($y->{_a}, $x->{_a}, 'accuracy');
    is($y->{_p}, $x->{_p}, 'precision');
};