updating copyright
[language-befunge.git] / t / 2-ops / math_addition.t
blob6e55191abdf69c3f0cac3c5cf9f97bf4835b542c
1 #!perl
3 # This file is part of Language::Befunge.
4 # Copyright (c) 2001-2009 Jerome Quelin, all rights reserved.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the same terms as Perl itself.
11 use Language::Befunge::Ops;
13 use strict;
14 use warnings;
16 use Language::Befunge::Interpreter;
17 use Language::Befunge::IP;
18 use Language::Befunge::Ops;
19 use Test::Exception;
20 use Test::More tests => 4;
22 my ($lbi, $ip, $v);
25 $lbi = Language::Befunge::Interpreter->new;
26 $ip  = Language::Befunge::IP->new;
27 $lbi->set_curip( $ip );
29 $ip->spush( 21, 42, 63 );
30 Language::Befunge::Ops::math_addition( $lbi );
31 is( $ip->spop, 105, 'math_addition pushes new value' );
32 is( $ip->spop, 21,  'math_addition pops only two values' );
34 # overflow
35 $ip->spush( 2**31-2, 3 );
36 throws_ok( sub { Language::Befunge::Ops::math_addition($lbi) },
37     qr/overflow/, 'math_addition barfs on overflow' );
39 # underflow
40 $ip->spush( -2**31+2, -3 );
41 throws_ok( sub { Language::Befunge::Ops::math_addition($lbi) },
42     qr/under/, 'math_addition barfs on underflow' );