Perl6-Pugs
view release on metacpan or search on metacpan
ext/Span/t/span.t view on Meta::CPAN
my @a = $span.difference( $span2 );
is( @a.elems, 1, 'difference span' );
is( @a[0].stringify, '[1,2)', 'difference 0' );
}
{
my @a = $span.difference( 2 );
is( @a.elems, 2, 'difference value' );
is( @a[0].stringify, '[1,2)', 'difference 0' );
is( @a[1].stringify, '(2,3]', 'difference 1' );
}
{
my $span = Span.new( :int, :start(1), :end(3) );
my @a = $span.difference( 2 );
is( @a.elems, 2, 'integer difference value' );
is( @a[0].stringify, '1', 'difference 0' );
is( @a[1].stringify, '3', 'difference 1' );
my @a = $span.difference( 3 );
is( @a.elems, 1, 'integer difference value end' );
is( @a[0].stringify, '[1,2]', 'difference 0' );
}
if 0
{
# XXX - this test should emit a warning - how to test this?
my $span = Span.new( :start(1), :end(2) );
my $iter = $span.iterator;
my $i;
is( $i = $iter.next, undef, 'iterator continuous' );
}
{
my $span = Span.new( :int, :start(1), :end(2) );
{
my $iter = $span.iterator;
my $i;
# say $i while $i = $iter.next;
is( $i = $iter.next, 1, 'iterator next 0' );
is( $i = $iter.current, 1, 'iterator currenct' );
$iter.reset;
is( $i = $iter.next, 1, 'iterator reset next 0' );
is( $i = $iter.next, 2, 'iterator next 1' );
is( $i = $iter.next, undef, 'iterator next 2' );
}
{
my $iter = $span.iterator;
my $i;
# say $i while $i = $iter.previous;
is( $i = $iter.previous, 2, 'iterator previous 0' );
is( $i = $iter.previous, 1, 'iterator previous 1' );
is( $i = $iter.previous, undef, 'iterator previous 2' );
}
{
my $iter = $span.iterator;
my $i;
my $x = coro {
loop {
my $n = $iter.next;
return unless defined $n;
yield $n
}
};
is( $i = $x(), 1, 'coro 0' );
is( $i = $x(), 2, 'coro 1' );
is( $i = $x(), undef, 'coro 2' );
}
{
my $i;
my $a;
while $a = $span.lazy {
is( $a, ++$i, "lazy $i" );
}
}
# XXX - fix me
# {
# my @a = $span.lazy;
# is( @a, "xxx", "lazy array" );
# }
}
{
my $span = Span.new( :int(1) );
{
my $iter = $span.iterator;
my $i;
is( $i = $iter.next, undef, 'next undef' );
}
{
my $iter = $span.iterator;
my $i;
is( $i = $iter.previous, undef, 'previous undef' );
}
}
{
# mixed types
my $span1 = Span.new( :start(1), :before(3) );
my $span2 = Span.new( :int, :start(1), :end(3) );
my ( $res1 ) = $span1.intersection( $span2 );
my ( $res2 ) = $span2.intersection( $span1 );
is( $res1.stringify, '[1,2]', 'intersection Num-Int' );
is( $res2.stringify, '[1,2]', 'intersection Int-Num' );
}
{
# mixed types, empty set
my $span1 = Span.new( :start(1), :before(3) );
my $span2 = Span.new( :density(1) );
my ( $res1 ) = $span1.union( $span2 );
my ( $res2 ) = $span2.union( $span1 );
is( $res1.stringify, '[1,2]', 'union Num-Int' );
is( $res2.stringify, '[1,2]', 'union Int-Num' );
}
( run in 0.904 second using v1.01-cache-2.11-cpan-d7f47b0818f )