Acme-Pythonic

 view release on metacpan or  search on metacpan

t/algorithms.t  view on Meta::CPAN

    my ($tree_link, $target, $cmp) = @_
    my $node

    while $node = $$tree_link:
        no warnings
        my $relation = defined $cmp ? $cmp->($target, $node->{val}) \
                                    : $target <=> $node->{val}
        return ($tree_link, $node) if $relation == 0
        $tree_link = $relation > 0 ? \$node->{left} : \$node->{right}

    return ($tree_link, undef)

sub basic_tree_add:
    my ($tree_link, $target, $cmp) = @_
    my $found

    ($tree_link, $found) = basic_tree_find($tree_link, $target, $cmp)
    unless $found:
        $found = {left  => undef,
                  right => undef,
                  val   => $target}
        $$tree_link = $found

    return $found

sub basic_tree_del:
    my ($tree_link, $target, $cmp) = @_
    my $found

    ($tree_link, $found) = basic_tree_find($tree_link, $target, $cmp)
    return undef unless $found
    if ! defined $found->{left}:
        $$tree_link = $found->{right}
    elsif ! defined $found->{right}:
        $$tree_link = $found->{left}
    else:
        MERGE_SOMEHOW($tree_link, $found)

    return $found->{val}

sub MERGE_SOMEHOW:

t/hop.t  view on Meta::CPAN



#
# ---[ Chapter 4: Iterators ]-------------------------------------------
#

# Defined on page 121
sub upto:
    my ($mx, $nx) = @_
    return sub:
        return $mx <= $nx ? $mx++ : undef

$it = upto 2, 5
my $n = 2
while defined(my $val = $it->()):
    is $val, $n++
is $n, 6

# Defined on page 122
sub NEXTVAL:
    $_[0]->()

t/hop.t  view on Meta::CPAN

            my $cur = pop @todo
            my ($target, $pool, $share) = @$cur

            my ($first, @rest) = @$pool

            push @todo, [$target, \@rest, $share] if @rest
            if $target == $first:
                return [@$share, $first]
            elsif $target > $first && @rest:
                push @todo, [$target-$first, \@rest, [@$share, $first]]
        return undef

my $mp = make_partitioner(5, [1, 2])
$expected = []
$computed = []
while my $p = NEXTVAL($mp):
    push @$computed, $p
is_deeply($expected, $computed)

$mp = make_partitioner(5, [1, 2, 3])
$expected = [[2, 3]]

t/noindent.t  view on Meta::CPAN


my $moo = "moo"
$moo =~ s:moo:foo:
is $moo, $foo

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

# Checks we don't see a comment in $#foo
my @foo = (0, 1)
my $n = 0
$#foo || undef $n
ok defined $n



( run in 4.759 seconds using v1.01-cache-2.11-cpan-d80b1682f3f )