Algorithm-CP-IZ

 view release on metacpan or  search on metacpan

t/00basic.t  view on Meta::CPAN

use strict;
use warnings;
use utf8;

use Test::More tests => 26;
BEGIN { use_ok('Algorithm::CP::IZ') };

my $iz = Algorithm::CP::IZ->new();
my $v1 = $iz->create_int(0, 10);


# save_context - restore_context pair works
# too many restore_context
{
    my $a = $iz->save_context;
    $v1->Le(5);
    my $b = $iz->save_context;
    $v1->Le(3);

    $iz->restore_context;
    is($v1->max, 5);
    $iz->restore_context;
    is($v1->max, 10);

    my $err = 1;
    eval {
        $iz->restore_context;
	$err = 0;
    };

    is($err, 1);
}

# save_context - restore_context_util works
{
    my $a = $iz->save_context;
    $v1->Le(5);
    my $b = $iz->save_context;
    $v1->Le(3);
    my $c = $iz->save_context;
    $v1->Le(2);

    $iz->restore_context_until($b); # state to before $b
    is($v1->max, 5);
    $iz->restore_context;
    is($v1->max, 10);

    my $err = 1;
    eval {
        $iz->restore_context;
	$err = 0;
    };

    is($err, 1);
}

# restore_all works
# invalid restore_context after restore_all
{
    my $a = $iz->save_context;
    $v1->Le(5);
    my $b = $iz->save_context;
    $v1->Le(3);



( run in 0.605 second using v1.01-cache-2.11-cpan-39bf76dae61 )