Math-DifferenceSet-Planar

 view release on metacpan or  search on metacpan

t/07_principals.t  view on Meta::CPAN

# Copyright (c) 2022-2025 Martin Becker, Blaubeuren.
# This package is free software; you can distribute it and/or modify it
# under the terms of the Artistic License 2.0 (see LICENSE file).

# The license grants freedom for related software development but does
# not cover incorporating code or documentation into AI training material.
# Please contact the copyright holder if you want to use the library whole
# or in part for other purposes than stated in the license.

# Before 'make install' is performed this script should be runnable with
# 'make test'. After 'make install' it should work as 'perl 07_principals.t'

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

use strict;
use warnings;
use File::Spec;
use FindBin;
use Config;
use Math::DifferenceSet::Planar;
use constant MDP => Math::DifferenceSet::Planar::;

use Test::More;
if (MDP->can('plane_principal_elements')) {
    plan tests => 106;
}
else {
    plan skip_all => 'principal elements not yet implemented';
}

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

my $ARITH_BITS = int 1.5+log(~0 >> 1)/log(2);

my $ds = MDP->new(16);
my $dz = $ds->zeta_canonize;
isa_ok($dz, MDP);

is($dz->zeta,  0, 'zeta-canonical zeta');
is($dz->eta,   0, 'zeta-canonical eta');
is($dz->theta, 0, 'zeta-canonical theta');

my $it = $ds->iterate_planes_zc;
is(ref($it), 'CODE', 'iterate planes using zeta-canonical sets');

my $di = $it->();
is($di->compare($dz), 0, 'first set');

$di = $it->();
is($di->zeta,  0, 'second set zeta');
is($di->eta,   0, 'second set eta');
is($di->theta, 0, 'second set theta');

my $c = 2;
while ($it->()) {
    ++$c;
}
is($c, 12, 'number of iterations');

my $dp = MDP->new(25);
$it = $dp->iterate_principal_planes_zc;
is(ref($it), 'CODE', 'iterate principal planes using zeta-canonical sets');

my $uc = $c = 0;
while (my $di = $it->()) {
    ++$c;
    ++$uc if $di->contains(1);
}
is($c, 2, 'number of principal planes');
is($uc, 2, 'number of principal planes containing principal element 1');

$it = $dp->iterate_planes_zc;
$uc = 0;
while (my $di = $it->()) {
    ++$uc if $di->contains(1);
}
is($uc, 2, 'number of planes containing principal element 1');

$it = $dp->iterate_principal_planes;
$uc = $c = 0;
while (my $di = $it->()) {
    ++$c;
    ++$uc if $di->contains(3);
}
is($c, 2, 'number of principal planes');
is($uc, 2, 'number of principal planes containing 013-set');

$it = $dp->iterate_planes;
$uc = $c = 0;
while (my $di = $it->()) {
    ++$c;
    ++$uc if $di->contains(3);
}
is($c, 60, 'number of planes');
is($uc, 2, 'number of planes containing 013-set');

my $lr = MDP->lex_reference(3);
SKIP: {
    skip "lex reference unknown", 3 if !defined $lr;
    is($lr->start_element, 0, 'lex reference');
    $lr = MDP->lex_reference(3, 1);
    is($lr->start_element, 0, 'lex reference with power');
    $lr = eval { MDP->lex_reference(127, 111) };
    is($lr, undef, 'no huge lex reference');
}

my $gr = MDP->gap_reference(3);
SKIP: {
    skip "gap reference unknown", 3 if !defined $gr;
    my ($e1, $e2) = $gr->largest_gap;
    is($e2, 0, 'gap reference');
    $gr = MDP->gap_reference(3, 1);
    ($e1, $e2) = $gr->largest_gap;
    is($e2, 0, 'gap reference with power');
    $gr = eval { MDP->gap_reference(127, 111) };
    is($gr, undef, 'no huge gap reference');
}



( run in 1.397 second using v1.01-cache-2.11-cpan-71847e10f99 )