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: Main.assertTrue(false); break;
     12             case 0: Main.assertTrue(false); break;
     13             case 1: /*correct*/ break;
     14             case 2: Main.assertTrue(false); break;
     15             case 3: Main.assertTrue(false); break;
     16             case 4: Main.assertTrue(false); break;
     17             default: Main.assertTrue(false); break;
     18         }
     19         switch (a) {
     20             case 3: Main.assertTrue(false); break;
     21             case 4: Main.assertTrue(false); break;
     22             default: /*correct*/ break;
     23         }
     24 
     25         a = 0x12345678;
     26 
     27         switch (a) {
     28             case 0x12345678: /*correct*/ break;
     29             case 0x12345679: Main.assertTrue(false); break;
     30             default: Main.assertTrue(false); break;
     31         }
     32         switch (a) {
     33             case 57: Main.assertTrue(false); break;
     34             case -6: Main.assertTrue(false); break;
     35             case 0x12345678: /*correct*/ break;
     36             case 22: Main.assertTrue(false); break;
     37             case 3: Main.assertTrue(false); break;
     38             default: Main.assertTrue(false); break;
     39         }
     40         switch (a) {
     41             case -6: Main.assertTrue(false); break;
     42             case 3: Main.assertTrue(false); break;
     43             default: /*correct*/ break;
     44         }
     45 
     46         a = -5;
     47         switch (a) {
     48             case 12: Main.assertTrue(false); break;
     49             case -5: /*correct*/ break;
     50             case 0: Main.assertTrue(false); break;
     51             default: Main.assertTrue(false); break;
     52         }
     53 
     54         switch (a) {
     55             default: /*correct*/ break;
     56         }
     57     }
     58 
     59     public static void run() {
     60         testSwitch();
     61     }
     62 }
     63