Acme-Aheui

 view release on metacpan or  search on metacpan

t/01_aheui.t  view on Meta::CPAN


    $interpreter->{_dx} = 0;
    $interpreter->{_dy} = 1;
    $interpreter->_move_cursor();
    is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [2, 1] );
    $interpreter->_move_cursor();
    is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [2, 2] );
    $interpreter->_move_cursor();
    is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [2, 3] );
    $interpreter->_move_cursor();
    is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [2, 4] );
    $interpreter->_move_cursor();
    is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [2, 0] );
    $interpreter->_move_cursor();
    is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [2, 1] );

    $interpreter->{_dy} = -1;
    $interpreter->_move_cursor();
    is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [2, 0] );
    $interpreter->_move_cursor();
    is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [2, 4] );

    $interpreter->{_dx} = 2;
    $interpreter->{_dy} = 0;
    $interpreter->_move_cursor();
    is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [0, 4] );
    $interpreter->_move_cursor();
    is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [2, 4] );
    $interpreter->_move_cursor();
    is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [0, 4] );

    $interpreter->{_dx} = -2;
    $interpreter->_move_cursor();
    is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [2, 4] );
    $interpreter->_move_cursor();
    is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [0, 4] );
    $interpreter->_move_cursor();
    is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [2, 4] );

    $interpreter->{_dx} = 0;
    $interpreter->{_dy} = 2;
    $interpreter->_move_cursor();
    is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [2, 0] );
    $interpreter->_move_cursor();
    is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [2, 2] );
    $interpreter->_move_cursor();
    is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [2, 4] );

    $interpreter->{_dy} = -2;
    $interpreter->_move_cursor();
    is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [2, 2] );
    $interpreter->_move_cursor();
    is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [2, 0] );
    $interpreter->_move_cursor();
    is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [2, 4] );
}

{ # storages

    my $counter = 0;
    sub test_stack {
        my ($interpreter, $storage_index) = @_;

        # a push and a pop
        my $in = $counter++;
        $interpreter->_push($storage_index, $in);
        my $out = $interpreter->_pop($storage_index);
        is( $in, $out );

        # pushes, pops
        my ($in1, $in2, $in3) = ($counter++, $counter++, $counter++);
        $interpreter->_push($storage_index, $in1);
        $interpreter->_push($storage_index, $in2);
        $interpreter->_push($storage_index, $in3);
        my $out3 = $interpreter->_pop($storage_index);
        my $out2 = $interpreter->_pop($storage_index);
        my $out1 = $interpreter->_pop($storage_index);
        is_deeply( [$in1, $in2, $in3], [$out1, $out2, $out3] );

        # duplicate
        my $first_in = $counter++;
        my $later_in = $counter++;
        $interpreter->_push($storage_index, $first_in);
        $interpreter->_push($storage_index, $later_in);
        $interpreter->_duplicate($storage_index);
        my $out_dup1 = $interpreter->_pop($storage_index);
        my $out_dup2 = $interpreter->_pop($storage_index);
        is( $later_in, $out_dup1 );
        is( $later_in, $out_dup2 );
        $interpreter->_pop($storage_index);

        # swap
        $first_in = $counter++;
        $later_in = $counter++;
        $interpreter->_push($storage_index, $first_in);
        $interpreter->_push($storage_index, $later_in);
        $interpreter->_swap($storage_index);
        my $first_out = $interpreter->_pop($storage_index);
        my $later_out = $interpreter->_pop($storage_index);
        is( $first_in, $first_out );
        is( $later_in, $later_out );
    }

    sub test_queue {
        my ($interpreter, $storage_index) = @_;

        # a push and a pop
        my $in = $counter++;
        $interpreter->_push($storage_index, $in);
        my $out = $interpreter->_pop($storage_index);
        is( $in, $out );

        # pushes, pops
        my ($in1, $in2, $in3) = ($counter++, $counter++, $counter++);
        $interpreter->_push($storage_index, $in1);
        $interpreter->_push($storage_index, $in2);
        $interpreter->_push($storage_index, $in3);
        my $out1 = $interpreter->_pop($storage_index);
        my $out2 = $interpreter->_pop($storage_index);
        my $out3 = $interpreter->_pop($storage_index);
        is_deeply( [$in1, $in2, $in3], [$out1, $out2, $out3] );

        # duplicate
        my $first_in = $counter++;
        my $later_in = $counter++;
        $interpreter->_push($storage_index, $first_in);
        $interpreter->_push($storage_index, $later_in);
        $interpreter->_duplicate($storage_index);
        my $out_dup1 = $interpreter->_pop($storage_index);
        my $out_dup2 = $interpreter->_pop($storage_index);
        is( $first_in, $out_dup1 );
        is( $first_in, $out_dup2 );
        $interpreter->_pop($storage_index);

        # swap
        $first_in = $counter++;
        $later_in = $counter++;
        $interpreter->_push($storage_index, $first_in);
        $interpreter->_push($storage_index, $later_in);
        $interpreter->_swap($storage_index);
        my $first_out = $interpreter->_pop($storage_index);
        my $later_out = $interpreter->_pop($storage_index);
        is( $first_in, $later_out );
        is( $later_in, $first_out );
    }

    my $interpreter = Acme::Aheui->new( source => '' );
    for my $i (0..26) {
        if ($i == 21) { # ã…‡ queue
            test_queue($interpreter, $i);
        }
        else { # '', ㄱ, ㄴ, ... ㅆ, ㅈ, .. ㅍ stack
            test_stack($interpreter, $i);
        }
    }
}

{ # termination code
    my $source = '밠히';
    my ($stdout, $stderr, @result) = capture {
        my $interpreter = Acme::Aheui->new( source => $source );
        $interpreter->execute();
    };
    is( $stdout, '' );



( run in 2.209 seconds using v1.01-cache-2.11-cpan-97f6503c9c8 )