/
13-op.t
54 lines (44 loc) · 1.52 KB
/
13-op.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!./parrot nqp.pbc
# checking basic operands and circumfix:( )
plan(33);
##Additive operators
ok( 1+2 == 3, 'Checking addition 1+2');
ok( 10-9 == 1, 'Checking subtraction 10-9');
ok( 10-3+2 == 9, 'Checking compound statements 10-3+2');
ok( 10-(3+2) == 5, 'Checking parenthesized statement 10-(3+2)');
##Multiplicative operators
ok( 6*7 == 42, 'Checking multiplication 6*7');
ok( 36/6 == 6, 'Checking division 36/6');
ok( 4*3+5 == 17, 'Checking compound statements 4*3+5');
ok( 4*(3+5) == 32, 'Checking parenthesized statements 4*(3+5)');
ok( 12/4*3 == 9, 'Checking compound statements 12/4*3');
ok( 12/(4*3) == 1, 'Checking compound statements 12/(4*3)');
ok( 5-3*2 == -1, 'Checking compound statements 5-3*2');
##Modulo operator
ok( 8%3 == 2, 'Checking modulo 8%3');
ok( 8%3+2 == 4, 'Checking compound statement 8%3+2');
ok( 8%(3+2) == 3, 'Checking compound statement 8%(3+2)');
##Concatenation operator
ok( 'a' ~ 'b' eq 'ab', 'Checking concatenation "a" ~ "b"');
ok( 1 ~ 'b' eq '1b', 'Checking concatenation 1 ~ "b"');
ok( 'a' ~ 2 eq 'a2', 'Checking concatenation "a" ~ 2 ');
##Postfix operators
my $x := 0;
ok( $x++ == 0 );
ok( $x == 1 );
ok( $x-- == 1 );
ok( $x == 0 );
##Relational operators
ok( ?(1 < 2) );
ok( !(2 < 1) );
ok( ?(2 <= 2) );
ok( !(3 <= 2) );
ok( ?(2 > 1) );
ok( !(2 > 3) );
ok( ?(2 >= 1) );
ok( !(2 >= 3) );
ok( !0.0 );
#Bitwise operators
ok( (1 +| 3) == 3, 'Checking 1 +| 3' );
ok( (3 +& 2) == 2, 'Checking 3 +& 2' );
ok( (3 +^ 3) == 0, 'Checking 3 +^ 3' );