added additional tests
[swftools.git] / lib / as3 / ok / ops.as
1
2 package {
3     import flash.display.MovieClip
4     public class Main extends flash.display.MovieClip {
5         var count:int = 1;
6         var num:int = 27;
7         function assert(b:Boolean) {
8             if(b) {
9                 trace("ok "+count+"/"+num);
10             } else {
11                 trace("error "+count+"/"+num);
12             }
13             count = count + 1
14         }
15         function Main() {
16             /* operations not tested here:
17                * comparison is tested in compare.as
18                * 'as' and 'is' are tested in typecast.as and extends.as
19                * ++ and -- are tested in assignments.as
20                * 'in' is tested by in.as
21                * || and && are tested in boolvalue.as
22                * <op>= is tested in assignments.as
23             */
24
25             /* test unary minus */
26             assert(-(3) == -3);
27
28             /* test tenary operator */
29             assert((true?1:2) == 1);
30             true?assert(1):assert(0);
31             false?assert(0):assert(1);
32
33             /* test other operators */
34             trace("[arithmetric]");
35             assert(3*3==9);
36             assert(3/3==1);
37             assert(10%4==2);
38             assert(2+3==5);
39             assert(2-3==-1);
40
41             /* test not */
42             trace("[not]");
43             assert(!false);
44             
45             /* test strict equals/unequals */
46             trace("[strict equals]");
47             assert(3===3);
48             assert(3!==4);
49             assert(!(3===4));
50             assert(!(3!==3));
51
52             /* test bit operations */
53             trace("[bit operations]");
54             assert(!(0xaaaaaaaa & 0x55555555))
55             assert((0xaa | 0x55) == 0xff);
56             assert((0xff ^ 0x55) == 0xaa);
57             assert((1 & ~1) == 0);
58             assert((1|~1)==~0);
59            
60             /* test shift operations */
61             trace("[shift operations]");
62             assert((0xff<<8)==0xff00);
63             assert((0xff>>4)==0x0f);
64             assert((-1>>1)==-1);
65             assert((-1>>1)==-1);
66             assert((-1>>>1)>0);
67
68             /* test typeof */
69             trace("[typeof]");
70             assert(typeof(3)=="number" && 
71                    typeof("")=="string" &&
72                    typeof(this)=="object" &&
73                    typeof(undefined)=="undefined" &&
74                    typeof(null)=="object" &&
75                    typeof(assert)=="function" &&
76                    typeof(Main)=="object");
77             
78             /* test void */
79             trace("[void]");
80             var v = void;
81             assert(String(v)=="undefined");
82
83             /* test comma */
84             assert( (1,2,3,4) == 4);
85         }
86     }
87 }
88