package jvmgo.book.ch07.test.instructions;

import static jvmgo.book.ch07.test.Assert.*;

public class SwitchTest {

    public static void main(String[] args) {
        assertTrue(chooseNear(0) == 0);
        assertTrue(chooseNear(1) == 1);
        assertTrue(chooseNear(2) == 2);
        assertTrue(chooseNear(3) == -1);

        assertTrue(chooseFar(-100) == -1);
        assertTrue(chooseFar(0) == 0);
        assertTrue(chooseFar(100) == 1);
        assertTrue(chooseFar(12) == -1);
    }

    // tableswitch
    private static int chooseNear(int i) {
        switch (i) {
            case 0:  return  0;
            case 1:  return  1;
            case 2:  return  2;
            default: return -1;
        }
    }

    // lookupswitch
    private static int chooseFar(int i) {
        switch (i) {
            case -100: return -1;
            case 0:    return  0;
            case 100:  return  1;
            default:   return -1;
        }
    }

}

@@ -182,32 +182,33 @@
 chooseNear(0) ==
+ 
  0);%0A        ass
@@ -227,24 +227,25 @@
 seNear(1) ==
+ 
  1);%0A       
@@ -272,16 +272,17 @@
 ar(2) ==
+ 
  2);%0A   
@@ -394,19 +394,23 @@
 seFar(0)
+   
  ==
+ 
  0);%0A   
@@ -439,19 +439,21 @@
 Far(100)
+ 
  ==
+ 
  1);%0A   
@@ -481,16 +481,18 @@
 eFar(12)
+  
  == -1);

format code