File: base_conversion.t

package info (click to toggle)
libmath-mpfr-perl 4.45-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,716 kB
  • sloc: perl: 1,508; ansic: 517; makefile: 9
file content (114 lines) | stat: -rwxr-xr-x 3,965 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
use strict;
use warnings;
use Test::More tests => 37;
use Math::MPFR qw(:mpfr);

# The relationship between mpfr_inter_prec() and mpfr_max_orig_len() that
# is present in the first 24 tests, does not always hold true. See tests
# 25..36 for example.
# However, that relationship should always hold true if $in[0] >= $in[2]
# (ie if old base >= new base), as tested in test 37.


my @in = (2, 53, 10, 17);

cmp_ok(mpfr_min_inter_prec($in[0], $in[1], $in[2]), '==', $in[3], 'test 1');
cmp_ok(mpfr_max_orig_len  ($in[0], $in[2], $in[3]), '==', $in[1], 'test 2');

@in = (10, 15, 2, 51);

cmp_ok(mpfr_min_inter_prec($in[0], $in[1], $in[2]), '==', $in[3], 'test 3');
cmp_ok(mpfr_max_orig_len  ($in[0], $in[2], $in[3]), '==', $in[1], 'test 4');

@in = (10, 16, 2, 55);

cmp_ok(mpfr_min_inter_prec($in[0], $in[1], $in[2]), '==', $in[3], 'test 5');
cmp_ok(mpfr_max_orig_len  ($in[0], $in[2], $in[3]), '==', $in[1], 'test 6');

@in = (2, 56, 16, 14);

cmp_ok(mpfr_min_inter_prec($in[0], $in[1], $in[2]), '==', $in[3], 'test 7');
cmp_ok(mpfr_max_orig_len  ($in[0], $in[2], $in[3]), '==', $in[1], 'test 8');

@in = (32, 1, 16, 2);

cmp_ok(mpfr_min_inter_prec($in[0], $in[1], $in[2]), '==', $in[3], 'test 9');
cmp_ok(mpfr_max_orig_len  ($in[0], $in[2], $in[3]), '==', $in[1], 'test 10');

@in = (32, 2, 16, 3);

cmp_ok(mpfr_min_inter_prec($in[0], $in[1], $in[2]), '==', $in[3], 'test 11');
cmp_ok(mpfr_max_orig_len  ($in[0], $in[2], $in[3]), '==', $in[1], 'test 12');


@in = (32, 4, 16, 5);

cmp_ok(mpfr_min_inter_prec($in[0], $in[1], $in[2]), '==', $in[3], 'test 13');
cmp_ok(mpfr_max_orig_len  ($in[0], $in[2], $in[3]), '==', $in[1], 'test 14');

@in = (32, 5, 16, 7);

cmp_ok(mpfr_min_inter_prec($in[0], $in[1], $in[2]), '==', $in[3], 'test 15');
cmp_ok(mpfr_max_orig_len  ($in[0], $in[2], $in[3]), '==', $in[1], 'test 16');

@in = (8, 15, 10, 15);

cmp_ok(mpfr_min_inter_prec($in[0], $in[1], $in[2]), '==', $in[3], 'test 17');
cmp_ok(mpfr_max_orig_len  ($in[0], $in[2], $in[3]), '==', $in[1], 'test 18');

@in = (8, 16, 10, 16);

cmp_ok(mpfr_min_inter_prec($in[0], $in[1], $in[2]), '==', $in[3], 'test 19');
cmp_ok(mpfr_max_orig_len  ($in[0], $in[2], $in[3]), '==', $in[1], 'test 20');

@in = (10, 15, 2, 51);

cmp_ok(mpfr_min_inter_prec($in[0], $in[1], $in[2]), '==', $in[3], 'test 21');
cmp_ok(mpfr_max_orig_len  ($in[0], $in[2], $in[3]), '==', $in[1], 'test 22');

@in = (8, 21, 10, 20);

cmp_ok(mpfr_min_inter_prec($in[0], $in[1], $in[2]), '==', $in[3], 'test 23');
cmp_ok(mpfr_max_orig_len  ($in[0], $in[2], $in[3]), '==', $in[1], 'test 24');

@in = (2, 80, 10, 26);

cmp_ok(mpfr_min_inter_prec($in[0], $in[1], $in[2]), '==', $in[3], 'test 25');
cmp_ok(mpfr_max_orig_len  ($in[0], $in[2], $in[3]), '!=', $in[1], 'test 26'); # $in[1] == 80
cmp_ok(mpfr_max_orig_len  ($in[0], $in[2], $in[3]), '==', 83,     'test 27');

@in = (8, 20, 10, 20);

cmp_ok(mpfr_min_inter_prec($in[0], $in[1], $in[2]), '==', $in[3], 'test 28');
cmp_ok(mpfr_max_orig_len  ($in[0], $in[2], $in[3]), '!=', $in[1], 'test 29'); # $in[1] == 20
cmp_ok(mpfr_max_orig_len  ($in[0], $in[2], $in[3]), '==', 21,     'test 30');

@in = (8, 14, 32, 9);

cmp_ok(mpfr_min_inter_prec($in[0], $in[1], $in[2]), '==', $in[3], 'test 31');
cmp_ok(mpfr_max_orig_len  ($in[0], $in[2], $in[3]), '!=', $in[1], 'test 32'); # $in[1] == 14
cmp_ok(mpfr_max_orig_len  ($in[0], $in[2], $in[3]), '==', 15,     'test 33');

@in = (2, 19, 16, 5);

cmp_ok(mpfr_min_inter_prec($in[0], $in[1], $in[2]), '==', $in[3], 'test 34');
cmp_ok(mpfr_max_orig_len  ($in[0], $in[2], $in[3]), '!=', $in[1], 'test 35'); # $in[1] == 19
cmp_ok(mpfr_max_orig_len  ($in[0], $in[2], $in[3]), '==', 20,     'test 36');

my $ok = 1;

for(1 .. 1000) {
  @in = (2 + int(rand(63)), 1 + int(rand(1000)), 2  + int(rand(63)));
  $in[3] = mpfr_min_inter_prec($in[0], $in[1], $in[2]);
  my $x = mpfr_max_orig_len($in[0], $in[2], $in[3]);
  if($x != $in[1] && $in[0] >= $in[2]) {
    warn "$x: @in\n";
    $ok = 0;
  }
}

cmp_ok($ok, '==', 1, 'test 37');