#!/usr/bin/perl -w
use
5.004;
plan
tests
=> 11;
MyTestHelpers::nowarnings();
{
my
$want_version
= 75;
ok (
$Math::NumSeq::HofstadterFigure::VERSION
,
$want_version
,
'VERSION variable'
);
ok (Math::NumSeq::HofstadterFigure->VERSION,
$want_version
,
'VERSION class method'
);
ok (
eval
{ Math::NumSeq::HofstadterFigure->VERSION(
$want_version
); 1 },
1,
"VERSION class check $want_version"
);
my
$check_version
=
$want_version
+ 1000;
ok (!
eval
{ Math::NumSeq::HofstadterFigure->VERSION(
$check_version
); 1 },
1,
"VERSION class check $check_version"
);
}
{
my
$seq
= Math::NumSeq::HofstadterFigure->new;
ok (!
$seq
->characteristic(
'smaller'
), 1,
'characteristic(smaller)'
);
ok (
$seq
->characteristic(
'integer'
), 1,
'characteristic(integer)'
);
ok (
$seq
->characteristic(
'increasing'
), 1,
'characteristic(increasing)'
);
ok (
$seq
->characteristic(
'non_decreasing'
), 1,
'characteristic(non_decreasing)'
);
ok (
$seq
->characteristic(
'increasing_from_i'
),
$seq
->i_start,
'characteristic(increasing_from_i)'
);
ok (
$seq
->characteristic(
'non_decreasing_from_i'
),
$seq
->i_start,
'characteristic(non_decreasing_from_i)'
);
}
{
my
$bad
= 0;
my
$max_diff
= 0;
foreach
my
$start
(1 .. 30) {
my
$seq
= Math::NumSeq::HofstadterFigure->new (
start
=>
$start
);
for
(
my
$rewind
= 0;
$rewind
< 2;
$rewind
++,
$seq
->rewind) {
my
@seen
;
if
(
$start
> 0) {
$seen
[0] = 1;
}
my
$prev_i
= 0;
my
$prev_value
;
my
$diff
;
foreach
(1 .. 500) {
my
(
$i
,
$value
) =
$seq
->
next
;
if
(
$i
!=
$prev_i
+1) {
MyTestHelpers::diag(
"oops i=$i, prev_i=$prev_i"
);
$bad
++;
}
if
(
$value
< 0) {
MyTestHelpers::diag(
"oops negative value=$value"
);
$bad
++;
}
if
(
$seen
[
$value
]) {
MyTestHelpers::diag(
"start=$start value $value already seen"
);
$bad
++;
}
if
(
$value
< 1100) {
$seen
[
$value
] = 1;
}
if
(
defined
$prev_value
) {
$diff
=
$value
-
$prev_value
;
if
(
$seen
[
$diff
]) {
MyTestHelpers::diag(
"start=$start diff $diff at i=$i value=$value already seen"
);
$bad
++;
}
$seen
[
$diff
] = 1;
}
$prev_i
=
$i
;
$prev_value
=
$value
;
}
foreach
my
$i
(0 ..
$diff
) {
if
(!
$seen
[
$i
]) {
MyTestHelpers::diag(
"start=$start value or diff $i not seeny"
);
$bad
++;
}
}
if
(
$diff
>
$max_diff
) {
$max_diff
=
$diff
;
}
}
}
ok (
$bad
, 0);
MyTestHelpers::diag(
"max_diff=$max_diff"
);
}
exit
0;