File: oeis-xrefs.t

package info (click to toggle)
libmath-planepath-perl 129-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 8,100 kB
  • sloc: perl: 115,748; ansic: 299; sh: 272; lisp: 73; makefile: 13
file content (231 lines) | stat: -rwxr-xr-x 7,671 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
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
#!/usr/bin/perl -w

# Copyright 2012, 2013, 2015, 2020, 2021 Kevin Ryde

# This file is part of Math-PlanePath.
#
# Math-PlanePath is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 3, or (at your option) any later
# version.
#
# Math-PlanePath is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License along
# with Math-PlanePath.  If not, see <http://www.gnu.org/licenses/>.


# Check that OEIS A-numbers listed in lib/Math/PlanePath/Foo.pm files have
# code exercising them in one of the xt/oeis/*-oeis.t scripts.
#
# Check that A-numbers are not duplicated among the .pm files, since that's
# often a cut-and-paste mistake.
#
# Check that A-numbers are not duplicated within an xt/oeis/*-oeis.t script,
# since normally only need to exercise a claimed path sequence once.  Except
# often that's not true since the same sequence can arise in separate ways.
# But for now demand duplication is either disguised there or explicitly
# listed here.
#


use 5.005;
use strict;
use FindBin;
use ExtUtils::Manifest;
use File::Spec;
use File::Slurp;
use Test::More;  # new in 5.6, so unless got it separately with 5.005
use List::Util 'uniqstr';

use lib 't','xt';
use MyTestHelpers;
BEGIN { MyTestHelpers::nowarnings(); }

# uncomment this to run the ### lines
#use Smart::Comments;

plan tests => 1;

my $toplevel_dir = File::Spec->catdir ($FindBin::Bin, File::Spec->updir);
my $manifest_filename = File::Spec->catfile ($toplevel_dir, 'MANIFEST');
my $manifest = ExtUtils::Manifest::maniread ($manifest_filename);
my $bad = 0;

my $anum_re = qr/A\d{6,7}/;


my %allow_POD_duplicates
  = (Corner => {A000290 => 1, # with different wider
                A002378 => 1, # with different wider
                A005563 => 1, # with different wider
                A014206 => 1, # with different wider
                A028552 => 1, # with different wider
               },
     DiamondSpiral => {A001105 => 1,  # different n_start
                      },
     CornerReplicate => {A139351 => 1,  # in text and seq list
                        },
     CoprimeColumns => {A002088 => 1,  # different n_start
                       },
     TerdragonCurve => {A057083 => 1,  # two uses
                       },
     AlternatePaper => {A062880 => 1,  # arms=1 and arms=2
                       },
    );

my %allow_checked_not_in_POD
  = (Corner => {A000007 => 1,  # left turn 1 at N=0 only
                A063524 => 1,  # left turn 1 at N=1 only
                A185012 => 1,  # left turn 1 at N=2 only
               },
     TriangleSpiralSkewed => {A081274 => 1,  # duplicate of A038764
                             },
     DragonCurve => {A059841 => 1,  # 1,0 repeating not interesting
                     A000035 => 1,  # 0,1 repeating
                    },
     DiagonalRationals => {A060837 => 1,  # checked in FactorRationals-oeis.t
                          },
    );


#------------------------------------------------------------------------------

# Entries like 'ZOrderCurve' => [ 'A000001', 'A000002', ... ]
my %path_seq_anums;
foreach my $seq_filename ('lib/Math/NumSeq/PlanePathCoord.pm',
                          'lib/Math/NumSeq/PlanePathN.pm',
                          'lib/Math/NumSeq/PlanePathDelta.pm',
                          'lib/Math/NumSeq/PlanePathTurn.pm',
                         ) {
  open my $fh, '<', $seq_filename or die "Cannot open $seq_filename";
  while (<$fh>) {
    if (/^\s*# OEIS-(Catalogue|Other):\s+($anum_re)([^#]+)/) {
      my $anum = $2;
      my @args = split /\s/, $3;
      my %args = map { split /=/, $_, 2 } @args;
      ### %args
      my $planepath_and_args = $args{'planepath'} || die "Oops, no planepath parameter";
      my ($planepath, @planepath_args) = split /,/, $planepath_and_args;
      push @{$path_seq_anums{$planepath}}, $anum;
    }
  }
}
foreach (values %path_seq_anums) {
  @$_ = uniqstr(@$_);
}

#------------------------------------------------------------------------------

my @module_filenames
  = grep {m{^lib/Math/PlanePath/[^/]+\.pm$}} keys %$manifest;
@module_filenames = sort @module_filenames;
diag "module count ",scalar(@module_filenames);
my @path_names = map {m{([^/]+)\.pm$}
                        or die "Oops, unmatched module filename $_";
                      $1} @module_filenames;

sub path_pod_anums {
  my ($planepath_name) = @_;
  my $filename = "lib/Math/PlanePath/$planepath_name.pm";
  open my $fh, '<', $filename
    or die "Oops, cannot open module filename $filename";
  my @ret;
  while (<$fh>) {
    if (/^ +($anum_re)/) {
      push @ret, $1;
    }
  }
  return @ret;
}

sub path_checked_anums {
  my ($planepath_name) = @_;
  return (path_xt_anums ($planepath_name),
          @{$path_seq_anums{$planepath_name} || []});
}
sub path_xt_anums {
  my ($planepath_name) = @_;
  my @ret;
  my %seen;
  foreach my $filename (File::Spec->catfile('xt','oeis',"$planepath_name-oeis.t"),
                        File::Spec->catfile('xt',"$planepath_name-hog.t")) {
    open my $fh, '<', $filename or next;
    while (<$fh>) {
      my $anum;
      # if (/^[^#]*\$anum = '($anum_re)'/mg) {
      if (/^[^#]*'($anum_re)'/mg) {
        $anum = $1;
      } elsif (/^[^#]*anum => '($anum_re)'/mg) {
        $anum = $1;
      } else {
        next;
      }
      push @ret, $anum;
      if ($seen{$anum}) {
        print "$filename:$.: duplicate check, previous at line $seen{$anum}\n";
        print "$filename:$seen{$anum}: ... previous here\n";
      } else {
        $seen{$anum} = $.;
      }
    }
  }
  return @ret;
}

# From among the argument strings, return those which appear more than once.
sub str_duplicates {
  my %seen;
  return map {$seen{$_}++ == 1 ? ($_) : ()} @_;
}

foreach my $planepath_name (@path_names) {
  my @pod_anums = path_pod_anums ($planepath_name);
  my @checked_anums = path_checked_anums ($planepath_name);

  my %pod_anums = map {$_=>1} @pod_anums;
  my %checked_anums = map {$_=>1} @checked_anums;

  foreach my $anum (str_duplicates(@pod_anums)) {
    next if $allow_POD_duplicates{$planepath_name}->{$anum};
    diag "Math::PlanePath::$planepath_name $anum duplicated within POD";
  }
  @pod_anums = uniqstr(@pod_anums);

  foreach my $anum (str_duplicates(@checked_anums)) {
    next if $anum eq 'A000012'; # all ones
    next if $anum eq 'A000027'; # 1,2,3 naturals
    next if $anum eq 'A005408'; # odd 2n+1
    diag "Math::PlanePath::$planepath_name $anum checked and also catalogued";
  }
  @checked_anums = uniqstr(@checked_anums);
  diag "";

  foreach my $anum (@pod_anums) {
    next if $anum eq 'A191689'; # CCurve fractal dimension
    if (! exists $checked_anums{$anum}) {
      diag "Math::PlanePath::$planepath_name $anum in POD, not checked";
    }
  }

  foreach my $anum (@checked_anums) {
    next if $anum eq 'A000004'; # all zeros
    next if $anum eq 'A000012'; # all ones
    next if $anum eq 'A001477'; # integers 0,1,2,3
    next if $anum eq 'A001489'; # negative integers 0,-1,-2,-3
    next if $anum eq 'A000035'; # 0,1 reps
    next if $anum eq 'A059841'; # 1,0 reps
    next if $allow_checked_not_in_POD{$planepath_name}->{$anum};
    if (! exists $pod_anums{$anum}) {
      diag "Math::PlanePath::$planepath_name $anum checked, not in POD";
    }
  }
}
is ($bad, 0);

#------------------------------------------------------------------------------

exit 0;