Home | History | Annotate | Download | only in src
      1 public class Switch {
      2     /**
      3      * Test switch() blocks
      4      */
      5     private static void testSwitch() {
      6         System.out.println("Switch.testSwitch");
      7 
      8         int a = 1;
      9 
     10         switch (a) {
     11             case -1: assert(false); break;
     12             case 0: assert(false); break;
     13             case 1: /*correct*/ break;
     14             case 2: assert(false); break;
     15             case 3: assert(false); break;
     16             case 4: assert(false); break;
     17             default: assert(false); break;
     18         }
     19         switch (a) {
     20             case 3: assert(false); break;
     21             case 4: assert(false); break;
     22             default: /*correct*/ break;
     23         }
     24 
     25         a = 0x12345678;
     26 
     27         switch (a) {
     28             case 0x12345678: /*correct*/ break;
     29             case 0x12345679: assert(false); break;
     30             default: assert(false); break;
     31         }
     32         switch (a) {
     33             case 57: assert(false); break;
     34             case -6: assert(false); break;
     35             case 0x12345678: /*correct*/ break;
     36             case 22: assert(false); break;
     37             case 3: assert(false); break;
     38             default: assert(false); break;
     39         }
     40         switch (a) {
     41             case -6: assert(false); break;
     42             case 3: assert(false); break;
     43             default: /*correct*/ break;
     44         }
     45 
     46         a = -5;
     47         switch (a) {
     48             case 12: assert(false); break;
     49             case -5: /*correct*/ break;
     50             case 0: assert(false); break;
     51             default: assert(false); break;
     52         }
     53 
     54         switch (a) {
     55             default: /*correct*/ break;
     56         }
     57     }
     58 
     59     public static void run() {
     60         testSwitch();
     61     }
     62 }
     63