File: P_specifier.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 (118 lines) | stat: -rwxr-xr-x 2,847 bytes parent folder | download | duplicates (2)
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
115
116
117
118
use strict;
use warnings;
use Math::MPFR qw(:mpfr);

print "1..6\n";

my $prec = 100009;
my ($fh, $RD);
my $file = 'p_spec.txt';
my $ok = '';
my $bytes = 7;

eval{Rmpfr_printf("hello world\n", 0);};
if($@) {
  warn "1a: \$\@: $@\n";
}
else {$ok .= 'a'};


eval{Rmpfr_printf("%Pu\n", 0, 0);};
if($@ =~ /In Rmpfr_printf: The rounding argument is specific to Math::MPFR objects/) {
  $ok .= 'b'
}
else {warn "1b: \$\@: $@\n"};

eval{Rmpfr_printf("%Pu\n", prec_cast($prec));};
if($@) {
  warn "1c: \$\@: $@\n";
}
else {$ok .= 'c'};


eval{Rmpfr_printf("%Pu\n", 0, prec_cast($prec));};
if($@ =~ /You've provided both a rounding arg and a Math::MPFR::Prec object to Rmpfr_printf/) {
  $ok .= 'd'
}
else {warn "1d: \$\@: $@\n"};

if($ok eq 'abcd') {print "ok 1\n"}
else {print "not ok 1\n"}

$ok = '';

######################################################

unless($ENV{SISYPHUS_SKIP}) {
  # Because of the way I (sisyphus) build this module with MS
  # Visual Studio, XSubs that take a filehandle as an argument
  # may not work. It therefore suits my purposes to be able to
  # avoid calling (and testing) those particular XSubs

  my $o = open($fh, '>', $file);
  if($o) {
    Rmpfr_fprintf($fh, "%Pu\n", prec_cast($prec));
    eval{Rmpfr_fprintf($fh, "%Pu\n", GMP_RNDN, prec_cast($prec));};
    if($@ =~ /You've provided both a rounding arg and a Math::MPFR::Prec object to Rmpfr_fprintf/) {$ok = 'a'}
    else {warn "2a: \$\@: $@\n"}
    close $fh;
    if(open($RD, '<', $file)) {
      my $num = <$RD>;
      chomp $num;
      if($num == $prec) {$ok .= 'b'}
      close($RD);
    }
    else { warn "Failed to open $file for reading: $!";}

    if($ok eq 'ab') {print "ok 2\n"}
    else {
      warn "\$ok: $ok\n";
      print "not ok 2\n";
    }
  }
  else {
    warn "Failed to open $file for writing: $!";
    warn "\nSkipping test 2 - couldn't open $file\n";
    print "ok 2\n";
  }
}
else {
  warn "\nskipping test 2 - \$ENV{SISYPHUS_SKIP} is set\n";
  print "ok 2\n";
}

#########################################################

my $buf;
Rmpfr_sprintf ($buf, "%Pu\n", prec_cast($prec), 200);

if($buf == 100009) {print "ok 3\n"}
else {
  warn "\$buf: $buf\n";
  print "not ok 3\n";
}

eval{Rmpfr_sprintf ($buf, "%Pu\n", GMP_RNDN, prec_cast($prec), 100);};
if($@ =~ /You've provided both a rounding arg and a Math::MPFR::Prec object to Rmpfr_sprintf/) {print "ok 4\n"}
else {
  warn "4: \$\@: $@\n";
  print "not ok 4\n";
}

Rmpfr_snprintf ($buf, $bytes, "%Pu\n", prec_cast($prec), 200);

chomp $buf;

if($buf == 100009) {print "ok 5\n"}
else {
  warn "\$buf: $buf\n";
  print "not ok 5\n";
}

eval{Rmpfr_snprintf ($buf, $bytes, "%Pu\n", GMP_RNDN, prec_cast($prec), 10);};
if($@ =~ /You've provided both a rounding arg and a Math::MPFR::Prec object to Rmpfr_snprintf/) {print "ok 6\n"}
else {
  warn "6: \$\@: $@\n";
  print "not ok 6\n";
}